How would I add a cool down to this script?

I have seen some posts about adding cool down, I attempted to use the tips but nothing stopped this script from letting you spam spawn a vehicle.

This is the script im trying to figure out how to make it so it has a timed cool down between clicks.

script.Parent.MouseButton1Click:connect(function(GetCar)
	Mod = game.ServerStorage.D40LF
	clone = Mod:clone()
	clone.Parent = workspace
    clone:MakeJoints() 

end)

I want to it so that the text box that is the parent will not initiated this code above and have a cool down of say 15 seconds. between clicks to stop spawning on top of eachother.

1 Like

Use a wait value and use debounce.

Here.

local debounce = false

script.Parent.MouseButton1Click:connect(function(GetCar)
    if debounce == true then return end
    debounce = true
	Mod = game.ServerStorage.D40LF
	clone = Mod:clone()
	clone.Parent = workspace
    clone:MakeJoints() 
    wait(15)
    debounce = false
end)

1 Like

Thank you so much, That worked perfectly! Made my life so much easier!

2 Likes