Hello, I was wondering how to make a GUI disappear when stepping of of a part. I believe I’m just missing very simple line in this script, but I’ve tried my hardest, does anybody know what I’m missing?
local Debounce = false
local UI = script:WaitForChild(‘UII’)
script.Parent.Touched:connect(function(Object)
local Player = game:GetService(‘Players’):GetPlayerFromCharacter(Object.Parent)
if Player and not Debounce then
Debounce = true
local PlayerGui = Player:WaitForChild('PlayerGui', 1)
if PlayerGui and not PlayerGui:FindFirstChild(UI.Name) then
UI:Clone().Parent = PlayerGui
wait(0.1)
Debounce = false
end
end
from what im seeing, Your script is trying to give the player a GUI and not make it disappear? But either way ill tell you the problem. You cant get PlayerGui from the server. You will need to communicate with the client when the part is stepped on to give the player said gui. Something like a RemoteEvent using :FireClient.
You would pretty much have to use magnitudes to detect if a Player is in range with a part, or maybe make a zone to detect so. Using TouchEnded isn’t very reliable when you use Touched along with it, so I wouldn’t recommend that.