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

How to wait until the item is placed again?

Asked by
jdflyer -9
7 years ago

I have a script that clones a torch, but I want it to wait 2 seconds before the next torch is placed. Where should I put the wait(2) and how should I do this?

script

Tool = script.Parent

function onButton1Down(mouse)

    local model = Tool.Torch:clone()

    model.Parent = game.Workspace
    model:MakeJoints()
    model:MoveTo(script.Parent.Parent.Humanoid.TargetPoint)



end

Tool.Activated:connect(onButton1Down)

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You could add a debounce in this. Because no matter where you add a "wait(2)" it will simply loop once you click. What you should do is this:

Tool = script.Parent
debounce=false

function onButton1Down(mouse)
if debounce==false then
debounce=true
    local model = Tool.Torch:clone()

    model.Parent = game.Workspace
    model:MakeJoints()
    model:MoveTo(script.Parent.Parent.Humanoid.TargetPoint)
wait(2)
debounce=false
else


end
end

Tool.Activated:connect(onButton1Down)

Just a lil explanation for this.

Basically the debounce is our "wait". When a player places a torch, it will go through the as normal, and place the torch. However, when it sets the torch it will also set the debounce value to true. Because the value is now true, it won't go on with the code and place another torch, but will just do nothing. Once the two minutes is up, the debounce goes back to false allowing another torch to be placed.

Ad

Answer this question