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

how can i make a car destroy itself after a certain amount of time when the player gets out?

1 answer

✓ Accepted answer

You can use the service Debris and it has a function perfect for you. It is :AddItem().

--Local script in any service that allows localscripts to run

local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")

humanoid.Seated:Connect(function(isSeated, seat) -- isSeated is whether the humanoid is sitting down, seat is the actual part.
	-- create a remote event in replicatedstorage
	game.ReplicatedStorage.RemoteEvent:FireServer(isSeated, seat) -- change RemoteEvent to the name that you have on your remoteEvent.
end)
-- Server script in serverscriptservice

local carModel = game.Workspace.Car -- change this with the name of the car model
local debris = game:GetService("Debris")

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, isSeated, seat)
	if not isSeated and seat then
		debris:AddItem(carModel, 30) -- add item basically schedules a deletion for a set amount of time. 
	end
end)

You can read more about Debris here (i'm a nice guy so i decided to help, even though you didn't try it.)

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