How would I make it show the gui for the player who touched on the part?

I am making it so if a player touches a part they open a gui, but everyone in the game sees it instead of the player who touches it. Local script

local player = game.Players.LocalPlayer
function Touch(hit)
    player.PlayerGui.ShopGui.Frame.Visible = true
end
workspace.ShopPart.Touched:Connect(Touch)
1 Like

Run an if statement to make inside the function checking if the hit.Parent = player.Character.

Your problem is that whenever the part is touched by anyone it will open it on local players screen. You need to make it so it fires when touched by only the local player.

1 Like

would I do

local player = game.Players.LocalPlayer

function Touch(hit)
	if hit.Parent == player.Character then
    	script.Parent.Frame.Visible = true
	end
end

workspace:WaitForChild("ShopPart").Touched:Connect(Touch)
1 Like

I believe that this will work.

1 Like

I am getting the error 12:58:17.263 - Frame is not a valid member of LocalScript

1 Like

The error is because you are referencing the Frame incorrectly.

You could switch line 5 back to this.

player.PlayerGui.ShopGui.Frame.Visible = true
1 Like

When I do that

local player = game.Players.LocalPlayer

function Touch(hit)
	if hit.Parent == player.Character then
    	player.PlayerGui.ShopGui.Frame.Visible = true
	end
end

workspace:WaitForChild("ShopPart").Touched:Connect(Touch)

it opens other gui as well