Basically I’m making a cart game and I want to add like a program that will blow up carts if nobody sits on them for like 2 minutes. However, how can I code it so that I know when the player leaves the seat, and start a timer.
You could use the Seat.Occupant property to determine whether or not the seat has an occupant. If it doesn’t have an occupant, wait 120 seconds (2 minutes) and then explode it if it doesn’t have an occupant still.
Example code snippet (it’s not very efficient I’m just doing it for the sake of the reply DO NOT C+P CUZ ITS INEFFICIENT)
local Timer = 0 if Seat.Occupant == nil then -- task.spawn(function() if you have code afterwards while task.wait(1) do if Timer == 120 and not Seat.Occupant then -- 2 minutes local Explosion = Instance.new(“Explosion”) -- explode the cart end if not Seat.Occupant then Timer += 1 else Timer = 0 end end
local Seat = workspace.Seat --Which seat we're checking? local AliveTime = 60*2 --How much time until it gets destroyed? function Destruct() --How should it be destroyed? local explosion = Instance.new("Explosion") explosion.Position = Seat.Position explosion.Parent = Seat print("Boom boom!") end local t = 0 while task.wait(1) do t = (Seat.Occupant and 0) or t+1 if t > AliveTime then Destruct() break end end