Gui pops up for everyone

I have this touch event local script located in StarterCharacterScript that works but has one major flaw. When a player steps on it, it pops up for everybody which is not something I want. Here is the script:

local player = game.Players.LocalPlayer
local part = game.Workspace.ShopPart -- Your Part's Path

part.Touched:Connect(function(hit)
	print("started")
	if hit.Parent:FindFirstChild("Humanoid") then
		player.PlayerGui.Shop.ShopGUI.Visible = true
		player.PlayerGui.Shop.Background.Visible = true


	end


end)

Im confused because I access localplayer and their playergui but the gui shows for everybody. How do I fix this?

Check if the hit object is the local player.

local player = game.Players.LocalPlayer
local part = game.Workspace.ShopPart -- Your Part's Path

part.Touched:Connect(function(hit)
	print("started")
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name == player.Name then
		player.PlayerGui.Shop.ShopGUI.Visible = true
		player.PlayerGui.Shop.Background.Visible = true


	end


end)
2 Likes