GUI script enables on all clients when activated

Greetings, I’ve been trying to get a GUI script to only appear on the client, but I’ve had a lot of trouble with this, and now I’m attempting to take this to the DevForum.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local GUI = Player.PlayerGui:WaitForChild("Dialogue")
	local function onClicked()
			GUI.Enabled = true
	end

	script.Parent.ClickDetector.MouseClick:connect(onClicked)

end)

This code works, although for whatever reason, it appears on all clients, not just the one that activated it. I’ve tried putting it in a localscript (and replacing the PlayerAdded function with just LocalPlayer), but to no avail, I’ve tried using remotes, and I’m pretty sure I did it correctly, but it didn’t work. Does anyone know why this is happening?

Try getting the player that clicked the click detector:

script.Parent .ClickDetector.MouseClick:Connect(function(plr)
    local GUI = plr.PlayerGui:WaitForChild("Dialogue")
    GUI.Enabled = true
end)
1 Like