Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can someone help me?

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

1 comment

0

Can you AT LEAST code block it?

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.