Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

1 comment

0

Yes that worked, but I had to remove the 'local' on line 06 for it to work.

This discussion is preserved as it was. New answers, comments, and votes are closed.