如何在Roblox中检查一下?
我正在Roblox中制作一个隐形药水。我的目标是做到这一点,以便您可以在本地看到您的角色,但是服务器中的其他所有人(不包括您)根本看不到您。
到目前为止,它在本地进行得很顺利,我将透明度设置为0.7,但是服务器部分是问题,每次我尝试使服务器检测到它是否正在与播放器或其他玩家打交道时。它似乎永远不起作用。
使用我现在的当前脚本,它将起作用,但是只有双击它,我只希望它不会感到困惑,而只是按照预期的方式工作。
这是我当前的两个本地和服务器。 本地:
local UIS = game:GetService("UserInputService")
script.Parent.Activated:Connect(function()
UIS.InputBegan:Connect(function(input, gpe)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local Player = script.Parent.Parent
script.Parent.EnableEvent:FireServer()
for _, child in ipairs(Player:GetChildren()) do
if child:IsA("BasePart") then
if child.Name == "HumanoidRootPart" then
child.Transparency = 1
else
child.Transparency = 0.7
end
elseif child:IsA("Accessory") then
child.Handle.Transparency = 0.7
end
end
wait(20)
for _, child in ipairs(Player:GetChildren()) do
if child:IsA("BasePart") then
if child.Name == "HumanoidRootPart" then
child.Transparency = 1
else
child.Transparency = 0
end
elseif child:IsA("Accessory") then
child.Handle.Transparency = 0
end
end
end
end)
end)
和服务器:
script.Parent.EnableEvent.OnServerEvent:Connect(function(player, Name)
local Player = script.Parent.Parent
if Name ~= script.Parent.Parent.Name then
for _, child in ipairs(Player:GetChildren()) do
if child:IsA("BasePart") then
child.Transparency = 1
elseif child:IsA("Accessory") then
child.Handle.Transparency = 1
end
end
wait(20)
for _, child in ipairs(Player:GetChildren()) do
if child:IsA("BasePart") then
if child.Name == "HumanoidRootPart" then
child.Transparency = 1
else
child.Transparency = 0
end
elseif child:IsA("Accessory") then
child.Handle.Transparency = 0
end
end
end
end)
最终结果看起来像这样: https://i.sstatic.net/fqj6p.jpg
I am making an invisibility potion in Roblox. My goal is to make it so that you can somewhat see your character locally, but everyone else in the server (not including you) can't see you at all.
So far it's going well, locally, I've set the transparency to 0.7, but the server part is the problem, every time I've tried to make the server detect if it was dealing with the player or other players. it just seemed to never work.
With the current scripts I have now, it will work, but only if you double click it, and I just want it to not get confused but just work as intended.
These are my two current scripts, local and server.
Local:
local UIS = game:GetService("UserInputService")
script.Parent.Activated:Connect(function()
UIS.InputBegan:Connect(function(input, gpe)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local Player = script.Parent.Parent
script.Parent.EnableEvent:FireServer()
for _, child in ipairs(Player:GetChildren()) do
if child:IsA("BasePart") then
if child.Name == "HumanoidRootPart" then
child.Transparency = 1
else
child.Transparency = 0.7
end
elseif child:IsA("Accessory") then
child.Handle.Transparency = 0.7
end
end
wait(20)
for _, child in ipairs(Player:GetChildren()) do
if child:IsA("BasePart") then
if child.Name == "HumanoidRootPart" then
child.Transparency = 1
else
child.Transparency = 0
end
elseif child:IsA("Accessory") then
child.Handle.Transparency = 0
end
end
end
end)
end)
And server:
script.Parent.EnableEvent.OnServerEvent:Connect(function(player, Name)
local Player = script.Parent.Parent
if Name ~= script.Parent.Parent.Name then
for _, child in ipairs(Player:GetChildren()) do
if child:IsA("BasePart") then
child.Transparency = 1
elseif child:IsA("Accessory") then
child.Handle.Transparency = 1
end
end
wait(20)
for _, child in ipairs(Player:GetChildren()) do
if child:IsA("BasePart") then
if child.Name == "HumanoidRootPart" then
child.Transparency = 1
else
child.Transparency = 0
end
elseif child:IsA("Accessory") then
child.Handle.Transparency = 0
end
end
end
end)
And the end result looks like this:
https://i.sstatic.net/fqj6P.jpg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我深入了解解决方案之前,这里是对正在发生的事情的解释。
仅当您启动远程事件时,它不会立即执行(由于客户端和服务器之间的延迟),因此客户端首先使所有内容透明,然后服务器覆盖该透明度,然后使所有内容完全透明。第二次点击使所有内容完全透明的原因是因为在您已经在透明度上的服务器上。
- 第二个点击
(第二次单击后,让您具有透明度.7)
因此,为了解决此问题,我们只需要等待服务器首先更改透明度,然后本地播放器应将其透明度更改为.7之后。我的建议是使用a 远程函数而不是远程函数事件。
与远程事件不同,在继续脚本之前,远程函数就像函数一样,并且在称为需求时完成/返回。
是的,您应该能够将代码更改为远程功能,这应该可以解决您的问题!
Before I dive into a solution, here's an explanation of what's going on.
Simply when you fire a remote event, it doesn't immediately execute (due to delay between the client and server) So the client is making everything .7 transparency, first and then the server overrides that and makes everything fully transparent. The reason why the second click makes everything fully transparent is because on the server you're already at transparency 1.
-- Second click
(Leaving you with transparency .7 after the second click)
So in order to solve this problem we just need to wait for the server to change the transparency first, then the local player should change their transparency to .7 after. My recommendation is to use a remote function instead of a remote event.
Unlike a remote event, a remote function acts like a function and when called needs complete/return before continuing the script.
So yeah, you should be able to just change your code to a remote function and that should hopefully solve your problem!