Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

If not seat.Occupant destroy but it still destroys when it is an occupant?

So, I just went on my fixed PC because the monitor was broken. Hello, I am trying to make code where if the car is not in use it will wait 10 seconds, then disappear. Except, it still disappears when the car is not in use. I found this out when I was testing my Renault.

local car = script.Parent 
local seat = script.Parent.DriveSeat
-- change the car and seat variables if they are different in your case.

seat.Changed:connect(function()
    if not seat.Occupant then
        wait(10)
        car:Destroy()
    end
end)

1 answer

✓ Accepted answer

Don't use seat.Changed, use this instead:

local car = script.Parent 
local seat = script.Parent.DriveSeat
-- change the car and seat variables if they are different in your case.

seat:GetPropertyChangedSignal("Occupant"):Connect(function(newOccupant)--Sets up the connection to when the Occupant changes it's value.
	if newOccupant == nil then--Checks if the new value is nil
		wait(10)
		if seat.Occupant == nil then--Checks if it is still nil
			car:Destroy()
		end
	end
end)

2 comments

0

Thanks.

0

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.