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

How can I edit my script so that 'wait()' works properly?

Below is a small script that allows a Hopperbin to spawn a model. I'm trying to add a cooldown so that it cannot be spammed but every attempt so far has failed.

bin = script.Parent

function onButton1Down(mouse)

local model = bin.Heal:clone() 
local unk = bin.test:clone()

model.Parent = game.Workspace
model:MakeJoints()
model:MoveTo(mouse.hit.p)
unk.Parent = model
unk.Disabled = false
wait(20)

end function onSelected(mouse) mouse.Icon = "rbxasset://textures\GunCursor.png" mouse.Button1Down:connect(function() onButton1Down(mouse) end) end

bin.Selected:connect(onSelected)

1 comment

0

acceot blue monkeys answer

1 answer

✓ Accepted answer

You just need to add a debounce:

bin = script.Parent

local debounce = true
function onButton1Down(mouse)
	if debounce then
		debounce = false
		local model = bin.Heal:clone() 
		local unk = bin.test:clone()
		model.Parent = game.Workspace
		model:MakeJoints()
		model:MoveTo(mouse.hit.p)
		unk.Parent = model
		unk.Disabled = false
		wait(20)
		debounce = true
	end
end 

function onSelected(mouse) 
	mouse.Icon = "rbxasset://textures\GunCursor.png" 
	mouse.Button1Down:connect(function() 
		onButton1Down(mouse) 
	end) 
end

bin.Selected:connect(onSelected)

2 comments

0

accept

0

Thankyou so much.

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