Ad
Log in to vote
0

When a zombie touches a part which makes GUI visible, it makes it visible for everyone?

Asked by 14 days ago
Edited 14 days ago

Directory: Game.StarterGui.ScreenGui.LocalScript

The script below is in LocalScript:

script.Parent.Frame.Visible = false

local brick = game.Workspace.shop
local player = game.Players.LocalPlayer


brick.Touched:Connect(function(hit)
    if hit and hit.Parent:FindFirstChild("Humanoid") then
        script.Parent.Frame.Visible = true 
    end
end) 

brick.TouchEnded:Connect(function(hit)
    if hit and hit.Parent:FindFirstChild("Humanoid") then
        script.Parent.Frame.Visible = false 
    end
end)

1 answer

Log in to vote
0
Answered by 14 days ago
Edited 14 days ago

Good day, hope you are doing well.

Basically, I think the issue is happening because you are connecting the touch event to the brick itself. This means that the event fires, when anybody touches the brick.

Instead, you have to check if that individual player touched that brick.

script.Parent.Frame.Visible = false

local brick = workspace.Shop
local player = game.Players.LocalPlayer

local debounce = false

brick.Touched:Connect(function(hit)
    if hit and hit.Parent:FindFirstChild("Humanoid") then
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid.Parent.Name == player.Name then
            if debounce == false then
                debounce = true
                script.Parent.Frame.Visible = true
            end
        end
    end
end) 

brick.TouchEnded:Connect(function(hit)
    if hit and hit.Parent:FindFirstChild("Humanoid") then
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid.Parent.Name == player.Name then
            if debounce == true then
                debounce = false
                script.Parent.Frame.Visible = false
            end
        end
    end
end)

I tried replicating this scenario in Roblox Studio, and this is what worked for me. The debounce variable is optional, but I would keep it to yield more accurate results and for performance.

0
Yes that worked, but I had to remove the 'local' on line 06 for it to work. itsmtninja 11 — 13d
Ad

Answer this question