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

I have a cooldown on my move but move decides to skip cooldown?

Asked by
iiii676 23
4 years ago
local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local debounce = false
script.Parent.MouseButton1Click:Connect(function()
    if Character.HumanoidRootPart.Anchored == false then
        if debounce == false then

            debounce = true

            if Player.leaderstats.Nature.Value == "Fire" then
                game.ReplicatedStorage.FireWall:FireServer()
            elseif Player.leaderstats.Nature.Value == "Grass" then
                game.ReplicatedStorage.GWall2:FireServer()
            elseif Player.leaderstats.Nature.Value == "Water" then
                game.ReplicatedStorage.WaWalk2:FireServer()
            end
        end
        wait(7)
        debounce = false
    end
end) --This is a local Script BTW

^^^ Here is my code, When I press the button, Sometimes I can use the move multiple times without waiting for the cooldown. Like there is no cooldown at all on the move. Anybody know why?

1 answer

Log in to vote
0
Answered by 4 years ago

I am not sure whether it will work or not, but try to keep your debounce in a single if statement. Here's an example :

local debounce = false

if debounce == false then
    debounce = true

    wait(7)
    debounce = false
end

-- And you did 
local debounce = false

if debounce == false then
    debounce = true
end

wait(7)
debounce = false

Lemme know if it helps!

0
Ill try this out! iiii676 23 — 4y
Ad

Answer this question