I have a brick that when touched a Gui will pop up on your screen. The only problem is, I can't figure out how to detect when the player is not on the brick, and have the script then destroy the Gui. I have tried script.destroy() but still nothing. Can someone please help me out with this?
local Gui = game.Lighting.World1 --Replace this with the location of your GUI
function GiveGui(Player)
if Player.PlayerGui:FindFirstChild(Gui.Name)~=nil then return end
Gui:Clone().Parent=Player.PlayerGui
end
script.Parent.Touched:connect(function(hit)
local Player=game.Players:GetPlayerFromCharacter(hit.Parent)
if Player==nil then return end
GiveGui(Player)
end)
