Car seat gui giver broken

Hello!
So this is a script inside a VehicleSeat to open a gui when a player is sitting in it, and close it when they jump out. It works for the first half- that is cloning the gui. The errors I am having are;

  • I cannot seem to hide the backpack, so lines 7 & 18 are wrong somehow.
  • The gui will not close once the person jumps out of the car seat. However, if they go into the car a second time, (therefore cloning the GUI, so there are 2 in the player’s gui) the script will remove one of them upon exiting the vehicle, but leave the other. So it kind of works?
function onChildAdded(something)

	if something.Name == "SeatWeld" then
		local human = something.part1.Parent:findFirstChild("Humanoid") 
		if (human ~= nil) then
			script.NEW:clone().Parent = game.Players:findFirstChild(human.Parent.Name).PlayerGui
			game.Players:findFirstChild(human.Parent.Name).PlayerGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		end
	end
end

function onChildRemoved(something)
	if (something.Name == "SeatWeld") then	
		local human = something.part1.Parent:findFirstChild("Humanoid") 
		if (human ~= nil) then
			print("Human Found")
			game.Players:findFirstChild(human.Parent.Name).PlayerGui.NEW:remove()
		    game.Players:findFirstChild(human.Parent.Name).PlayerGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

		end
	end
end


script.Parent.ChildAdded:connect(onChildAdded)
script.Parent.ChildRemoved:connect(onChildRemoved)

Should be FindFirstChild.

Use GetService instead.

Players:GetPlayerFromCharacter(human.Parent).PlayerGui would be better.

Deprecated, use Destroy() instead.

This can only be done on the client. You need to do this from a LocalScript or a Script with a Client RunContext.

should be FindFirstChildWhichIsA("Humanoid")

1 Like