Help how can I make this gui pop up only on one players screen?

Hello! So what I want is that when a player touches a trigger part in the workspace a shop gui pops up for them. I made the script in a local script and put it in starterplayerscripts. Yet the gui pops up for everyone on the server how can I fix this?

local Sensor = game.Workspace:WaitForChild(“Sensor”)

local ShopToolGui = game.ReplicatedStorage:WaitForChild(“ShopToolGui”)

local player = game.Players.LocalPlayer

Sensor.Touched:Connect(function(hit)

local Humanoid = hit.Parent:FindFirstChild(“Humanoid”)

if Humanoid ~= nil then

local Clone = ShopToolGui:Clone()

ShopToolGui.Parent = player.PlayerGui

end

end)

My guess is both scripts are detecting that the part was touched, and because the script doesn’t care about what client touched it, the gui shows up on every client’s screen. To fix this, you can just make the gui show up on hit’s playergui:

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
ShopToolGui.Parent = player.PlayerGui

Hopefully this works!

2 Likes

I figured it out just like after I posted it lmao I couldn’t figure it out but then I was like what can I do? I decided to use the players name and to check it with an if statement if the players name matched up with who touched it and to show it only to that players name and it actually worked! But thank you anyways!

2 Likes

I know this post was already solved but you should use @dodle120 way since it’s more efficient.