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

How do I make this have a cool-down time?

Asked by 5 years ago

I made this script in order to spawn an object when a button is pressed and that part works, but the problem is when I tried to make a cool-down. Now, it is just always showing as ready = 1 and never 0 so there is no cool-down. Why?

local ready = script.Parent.Parent.Ready.Value
local Spawner = Vector3.new(157.326, 8.715, 26.577)
local Clicker = script.Parent 
    local Object = game.ReplicatedStorage:WaitForChild("Cardboard")
    local ObjectSpawn = script.Parent.Parent.Spawn 
    local ready = 1

    if ready == 1 then
        Clicker.MouseClick:Connect(function()
        ready = 0
        local CloneObject = Object:Clone()
        CloneObject.Parent = game.Workspace 
        CloneObject:MoveTo(Spawner)
        wait (12)
    end )
    ready = 1
end

if ready == 0 then
    script.Parent.Parent.BrickColor=BrickColor.new("Bright red")
    print("ready = 0")
else
    print ("Ready = 1")
end
0
Add a debounce TheOneKingx 7 — 5y

1 answer

Log in to vote
0
Answered by
Optikk 499 Donator Moderation Voter
5 years ago
Edited 5 years ago

This is easy to accomplish. Here is a simple example of a debounce:

local debounce = false -- this doesn't need to be named debounce, just preference.

Clicker.MouseClick:Connect(function()
    if not debounce then

        -- by setting debounce to true, we will keep this code from executing
        -- too quickly. "if not debounce then" ensures this. It is about the
        -- same as "if debounce == false then"
        debounce = true

        -- here, you just put what you want to happen when the button
        -- is clicked
        print('Clicker was clicked!')

        wait(3) -- wait a period of time before setting debounce to false
        debounce = false

        -- now that debounce is false again, this code can execute next
        -- time Clicker.MouseClick is fired
    end
end)

Just apply this to your own code, defining the appropriate variables. Please comment if you have any questions.

0
Thx for this I actually was about to mark this question as answered because I figured out how to use a debounce, and this is near exact to what I had. Thanks Again! KingCheese13 21 — 5y
Ad

Answer this question