How can I make the GUI appear when a player comes in contact with a brick and then go away when they move away from it. Someone told me it was with magnitudes but I tried it out and it didn't work for some reason. Since nothing popped up.
function touch(hit)
if game.Players:findFirstChild(hit.Parent.Name) ~= nil then
local player = game.Players[hit.Parent.Name]
if player.PlayerGui:findFirstChild("Shop") == nil then
local gui = script.Shop:clone()
gui.Parent = player.PlayerGui
repeat
wait()
until (player.Character.Torso.Position - script.Parent.Position).magnitude > 5
gui:remove()
end
end
end
script.Parent.Touched:connect(touch)

1 comment
you can use :GetPlayerFromCharacter instead of game.Players[hit.Parent.Name], GetPlayerFromCharacter avoids the possibility of having another non-player object named the same as hit.Parent and selecting that instead of the player