I have a part surrounding the chest and then a script inside of it. But Nothing happens. I want the GUI to appear and then if you walk to it again it gets closed.
local storage = game:GetService("ServerStorage") local gui = storage.CarUI local part = workspace.ChestTrigger local deb = false local path = game.Players.LocalPlayer.PlayerGui.CarUI part.Touched:connect(function() if (deb == false) then gui:Clone().Parent = game.Players.LocalPlayer.PlayerGui wait(2) deb = true elseif (deb == true) then path:Destroy() deb = false end end)
PLEASE help me.
I suggest making a button on your gui to close it, because Touching the part will be inaccurate.
LocalPlayer
from server scripts. You have to retrieve the player based on who touched the Part using the GetPlayerFromCharacter
function.local gui = game.ServerStorage.CarUI local part = workspace.ChestTrigger local deb = false part.Touched:connect(function(hit) --'hit' is the part that touched if not db then db = true local plr = game.Players:GetPlayerFromCharacter(hit.Parent) --If player exists, and gui doesn't if plr and not plr.PlayerGui:FindFirstChild(gui.Name) then gui:Clone().Parent = plr.PlayerGui --Clone it end db = false end end)
A close button for a gui would use the MouseButton1Down
event in a LocalScript, and look like this:
script.Parent.MouseButton1Down:Connect(function() --button clicked script.Parent.Parent.Parent:Destroy() --destroy ScreenGui end)
Hierarchy of UI:
ScreenGui
Frame
TextButton