Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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)

1local model = bin.Heal:clone()
2local unk = bin.test:clone()
3 
4model.Parent = game.Workspace
5model:MakeJoints()
6model:MoveTo(mouse.hit.p)
7unk.Parent = model
8unk.Disabled = false
9wait(20)

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

bin.Selected:connect(onSelected)

0
acceot blue monkeys answer abnotaddable 920 — 7y

1 answer

Log in to vote
2
Answered by 7 years ago

You just need to add a debounce:

01bin = script.Parent
02 
03local debounce = true
04function onButton1Down(mouse)
05    if debounce then
06        debounce = false
07        local model = bin.Heal:clone()
08        local unk = bin.test:clone()
09        model.Parent = game.Workspace
10        model:MakeJoints()
11        model:MoveTo(mouse.hit.p)
12        unk.Parent = model
13        unk.Disabled = false
14        wait(20)
15        debounce = true
View all 26 lines...
0
accept abnotaddable 920 — 7y
0
Thankyou so much. Meerkatclaw06 6 — 7y
Ad

Answer this question