如何在Roblox中检查一下?

发布于 2025-01-26 20:27:00 字数 2637 浏览 1 评论 0原文

我正在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾忌 2025-02-02 20:27:00

在我深入了解解决方案之前,这里是对正在发生的事情的解释。

仅当您启动远程事件时,它不会立即执行(由于客户端和服务器之间的延迟),因此客户端首先使所有内容透明,然后服务器覆盖该透明度,然后使所有内容完全透明。第二次点击使所有内容完全透明的原因是因为在您已经在透明度上的服务器上。

  1. 播放器透明度设置为.7
  2. 服务器透明度设置为1透明度,并覆盖本地透明度

- 第二个点击

  1. 播放器透明度设置了到.7
  2. 服务器透明度已经为1,因此不会更改它。
    (第二次单击后,让您具有透明度.7)

因此,为了解决此问题,我们只需要等待服务器首先更改透明度,然后本地播放器应将其透明度更改为.7之后。我的建议是使用a 远程函数而不是远程函数事件。

与远程事件不同,在继续脚本之前,远程函数就像函数一样,并且在称为需求时完成/返回。

-- Example
-- server
local remoteFunction = game.ReplicatedStorage.RemoteFunction
remoteFunction.OnServerInvoke = function(player)
    wait(5)
end

-- client
local remoteFunction = game.ReplicatedStorage.RemoteFunction

remoteFunction:InvokeServer()
print("Hello World") -- is delayed by 5 seconds since the function call needs to finish

是的,您应该能够将代码更改为远程功能,这应该可以解决您的问题!

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.

  1. Player Transparency is set to .7
  2. Server Transparency is set to 1 transparency and overriding the local transparency

-- Second click

  1. Player Transparency is set to .7
  2. Server Transparency is already 1 so it doesn't change it.
    (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.

-- Example
-- server
local remoteFunction = game.ReplicatedStorage.RemoteFunction
remoteFunction.OnServerInvoke = function(player)
    wait(5)
end

-- client
local remoteFunction = game.ReplicatedStorage.RemoteFunction

remoteFunction:InvokeServer()
print("Hello World") -- is delayed by 5 seconds since the function call needs to finish

So yeah, you should be able to just change your code to a remote function and that should hopefully solve your problem!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文