I am making a create car button not working

So it works but it doesn’t have a cooldown. I have put wait() in different spots to try and get a cooldown nothing is working.
Script:

location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()

script.Parent.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("HumanoidRootPart") then
	
	wait(10)
	back = save:clone()
	back.Parent = location
	back:MakeJoints()

end
end)

Events that contain wait() or task.wait() can overlap with each other (run at the same time of each other, asynchronously), because while the wait() is called the first time the event is fired, the event can be fired again, making it run again. To prevent this, just include a simple debounce variable:

location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()

debounce = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") and debounce == false then
		back = save:clone()
		back.Parent = location
		back:MakeJoints()
		debounce = true
		wait(10)
		debounce = false
	end
end)

The debounce is set to true before the wait, and the if statement checks if debounce is false before it moves on, so it won’t run. After the wait, the debounce is set back to false.

I also recommend using local for your variables unless you need them to be available to your whole script.

Ill try this but i tried something with debounce that didn’t work.

still lagged out the game


best screen shot i could have gotten i have to restart studio now

This is happening because you’re cloning the regen button too.