Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help me?

Asked by 9 years ago

i have this so far, but am not that experienced and need help, im making a city world, and i dont want the gui for everyone, just the coldstone workers, so i have a handto gui on the chairs and it works but i need help making it dissappear when the person gets out of the chair i have this so far:

local Gui = game.Lighting.HandtoGUI

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)

will someone help me add more so when the person is not touching it, it dissapears

0
Can you AT LEAST code block it? groovydino 2 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Use TouchEnded.

local Gui = game.Lighting.HandtoGUI

function GiveGui(Player)
    if Player.PlayerGui:FindFirstChild(Gui.Name)~=nil then return end
    Gui:Clone().Parent=Player.PlayerGui
end
function RemoveGui(Player)
    local gui = Player.PlayerGui:FindFirstChild(Gui.Name)
    if gui then gui:Destroy() end
end

script.Parent.Touched:connect(function(hit)
    local Player=game.Players:GetPlayerFromCharacter(hit.Parent)
    if Player==nil then return end
    GiveGui(Player)
end)
script.Parent.TouchEnded:connect(function(hit)
    local Player=game.Players:GetPlayerFromCharacter(hit.Parent)
    if Player==nil then return end
    RemoveGui(Player)
end
Ad

Answer this question