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 6 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)

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)

0
acceot blue monkeys answer abnotaddable 920 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago

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)
0
accept abnotaddable 920 — 6y
0
Thankyou so much. Meerkatclaw06 6 — 6y
Ad

Answer this question