GUI Not Disappearing

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

end)

3 Likes

Did you perhaps make sure that your UI is enabled/visible?


Also, just a reminder to copy and paste your code onto the DevForum instead of screenshotting it.

3 Likes

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.

2 Likes

im trying to get the GUI to appear and disappear once the player steps of the part, i do not know how to make it disappear though.

2 Likes

I added the script to the post.

2 Likes

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.

3 Likes

I don’t know how to do that really, scripting is not my strong suit, i will try to google some guides or something.

2 Likes

Oh. Then use .TouchEnded To remove the GUI from the player. Which isnt reliable. I could give you some alternatives though.

3 Likes

You can try to use the ZonePlus Plugin to build zones to detect when the Player enter/leaves a zone.

2 Likes

Ill try that. Send some alternatives just in case, if you don’t mind.

2 Likes

Refer to what @Deb0rahAliWilliams posted. ZonePlus should do what you’re trying to achieve pretty easily!

3 Likes