The player sits down, gets out of the vehicle seat, if for 5 minutes no one sits on this seat, vehicle:Destroy()
How can i do that ?
i already tried the
task.wai(…)
if vehicleSeat.Occupant then …
but it doesn’t work
The player sits down, gets out of the vehicle seat, if for 5 minutes no one sits on this seat, vehicle:Destroy()
How can i do that ?
i already tried the
task.wai(…)
if vehicleSeat.Occupant then …
but it doesn’t work
You can make use of delayed threads:
--!strict
local vehicleSeat: VehicleSeat = script.Parent
local destroyThread: thread? = nil
local DESTROY_TIME: number = 5
vehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function(): ()
if vehicleSeat.Occupant ~= nil and destroyThread ~= nil then
print("cancelled")
task.cancel(destroyThread)
destroyThread = nil
elseif vehicleSeat.Occupant == nil and destroyThread == nil then
print("destroying")
destroyThread = task.delay(DESTROY_TIME, function(): ()
destroyThread = nil
vehicleSeat:Destroy()
end)
end
end)
I haven’t had time to do it yet, but I think it will be perfect! THANKS !
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.