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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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

Answer this question