Code isn't doing what I scripted it to do?

Hey. I’m trying to get a GUI to close once the player jumps out of the seat (which is the parent of the script), and it is giving the GUI, but not removing it or erroring or anything when I jump out of the seat.

Server script:

local seat = script.Parent
local lastPlayer = nil

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		local humanoid = seat.Occupant
		local plr = game.Players:FindFirstChild(humanoid.Parent.Name)
		lastPlayer = plr

		local copy = game:GetService("ServerScriptService"):WaitForChild("CheckIn"):WaitForChild("UI"):WaitForChild("CheckInController"):Clone()
		copy:WaitForChild("Desk").Value = script.Parent:WaitForChild("Desk").Value
		copy.Parent = plr:WaitForChild("PlayerGui")
	else
		lastPlayer:WaitForChild("PlayerGui"):WaitForChild("CheckInController"):Destroy()
	end
end)

Any help appreciated!

Have you tried printing anything out, for example to check if it is actually running the code to delete the gui in the first place? I always find printing out values helps greatly with debugging.

I wasn’t able to reproduce this issue myself.
You seem to have a lot of WaitForChilds, did you check if any of them yield?
Also as a side note, it is a bad practice to have WaitForChild on a server script, everything will always already be loaded in on a server script.

image


Still not working

Hmm… are there multiple clones of the GUI? Maybe it’s deleting one but not the other.

1 Like

Thanks for the tip, none of them yields, and I get no reply from the Output for any issues, yields, or anything similar.


I modified your script to test it for myself, and it was working just fine.
Could you check if there is more than one so called “CheckInController” in your PlayerGui while you are seated?

1 Like

Seems like i found that out the hard way! Just realized I forgot to rename the development GUI, so that’s the one that was getting deleted. It’s fully working now. Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.