Cooldown for Car Script

Hello fellow developers, I have a script in the game that spawns a car when the player steps on the button, but I cannot figure out how to make a certain amount of time before the player can spawn another car :frowning: Please help…

Here is script number one

system = script.Parent

model = system.Station –

backup = model:Clone()

regen = system.Regen

function checkRegen()

if regen.Value == 1 then



	wait(1)

	model = backup:Clone()

	model.Parent = system

	model:MakeJoints()

end

end

regen.Changed:connect(checkRegen)

and script number two is

button = script.Parent

regen = button.Parent.Regen

local debounce = false

function onTouch(hit)

local h = hit.Parent:FindFirstChild("Humanoid")

if h ~= nil and debounce == false then

	debounce = true

	button.BrickColor = BrickColor.Black()

	regen.Value = 1

	wait(1)

	regen.Value = 0

	wait(5)

	button.BrickColor = BrickColor.new(104)

	debounce = false

end

end

button.Touched:connect(onTouch)

1 Like

Well, it looks like there already is a wait(1) and a wait(5) before the player is able to spawn a car again. Do those not work?

ok @Queegly did not tell me that he put a wait script into the game thank you for helping me I was too lazy to look at the script thanks :slight_smile:

1 Like