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

Where do I put a wait in this script so people don't spam the regen?

I've got a script here that takes a humble from server storage and copies it then places it into workspace. However, I don't know where to put a wait so people don't spam the regen. Where do I put it? Everywhere I put it, the script just ignores it and moves on?

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

1 answer

✓ Accepted answer

Simply putting wait() anywhere will not work, because a new thread is created anyway when the player clicks on the mouse again. What you need to do is use a variable to make sure there's a delay before it can be pressed again, like this:

local debounce = false --Set up the variable

script.Parent.MouseButton1Click:Connect(function(GetCar)
	if debounce == false then
		debounce = true --The function can't run again until this is turned back to false
   		Mod = game.ServerStorage.Humvee 
        	clone = Mod:clone()
        	clone.Parent = workspace
        	clone:MakeJoints()
		wait(3) --Here you can adjust the time it takes before you can click it again
		debounce = false --Debounce is false again, you can now click it again
	end
end)

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