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

Car spawner breaks car despawner?

Hello, I am trying to make a system where if you spawn a car, you have 10 seconds to get in before it despawns. This is for a game called Track8 but it seems that the spawner breaks the despawner. Note: MouseButton1Click and wait(1) are placeholders Car spawner:

script.Parent.MouseButton1Click:connect(function(GetCar)
		local Mod = game.ServerStorage.RallyRenault     --Change test to whatever you have named the item you want to spawn
		local clone = Mod:Clone()
		clone.DeSpawn.Disabled = false
		clone.Name = "RallyRenaultClone"
		clone.Parent = workspace
		clone:MakeJoints()
end)

Despawner:

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(1)
        if seat.Occupant == nil then--Checks if it is still nil
            car:Destroy()
        end
    end
end)

2 comments

0

change workspace to game.workspace and for the despawner do a wait

0

Where? Also the despawner also has a wait.

1 answer

Well, It works, but it only works for cars that had a driver. Focus on this reply from now on answerers.

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