Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

Directory: Game.StarterGui.ScreenGui.LocalScript

The script below is in LocalScript:

01script.Parent.Frame.Visible = false
02 
03local brick = game.Workspace.shop
04local player = game.Players.LocalPlayer
05 
06 
07brick.Touched:Connect(function(hit)
08    if hit and hit.Parent:FindFirstChild("Humanoid") then
09        script.Parent.Frame.Visible = true
10    end
11end)
12 
13brick.TouchEnded:Connect(function(hit)
14    if hit and hit.Parent:FindFirstChild("Humanoid") then
15        script.Parent.Frame.Visible = false
16    end
17end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years 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.

01script.Parent.Frame.Visible = false
02 
03local brick = workspace.Shop
04local player = game.Players.LocalPlayer
05 
06local debounce = false
07 
08brick.Touched:Connect(function(hit)
09    if hit and hit.Parent:FindFirstChild("Humanoid") then
10        local humanoid = hit.Parent:FindFirstChild("Humanoid")
11        if humanoid.Parent.Name == player.Name then
12            if debounce == false then
13                debounce = true
14                script.Parent.Frame.Visible = true
15            end
View all 30 lines...

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 — 2y
Ad

Answer this question