I am having trouble making a GUI pop up when the player is touching a part, but then the GUI disappears when the player is not touching the part.
The part that I want the player to touch and activate the GUI is called 'Part'. The GUI is called 'GUI'.
The tree goes like this, Workspace > Part > Script > GUI
This is the code I have so far:
script.Parent.Touched:connect(function(char) local player = game.Players:GetPlayerFromCharacter(char) if player and not player.PlayerGui.GUI then script.GUI:clone().Parent = player.PlayerGui end end) script.Parent.TouchEnded:connect(function(char) local player = game.Players:GetPlayerFromCharacter(char) if player and player.PlayerGui.GUI then player.PlayerGui.GUI:Destroy() end end)
When I test, the GUI just doesn't come up on screen when I touch the part.
How do I fix this??
I have left some comments for you to read. If this helped, please accept my answer :)
script.Parent.Touched:Connect(function(hit) -- The parameter would not be the character, it would be the part that touches script.Parent local player = game.Players:GetPlayerFromCharacter(hi.Parent) -- hit.Parent is the character if player and not player.PlayerGui:FindFirstChild('GUI') script.GUI:Clone().Parent = player.PlayerGui -- "clone()" should have a capital "C" end end) script.Parent.TouchEnded:Connect(function(hit) -- Also, connect should be with a capital "C". local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player and player.PlayerGui:FindFirstChild('GUI') then player.PlayerGui.GUI:Destroy() end end)