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

My cooldown keeps getting bypassed?

Asked by 1 year ago

I have a sword ability but when you spam R it keeps playing completely disregarding the cooldown, can someone help me?

Local Script inside of tool

local UIS = game:GetService("UserInputService")
local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()

local Equipped = false
local Cooldown = false


script.Parent.Equipped:Connect(function()
    Equipped = true
    print(Equipped)
end)

script.Parent.Unequipped:Connect(function()
    Equipped = false
    print(Equipped)
end)

while true do
    wait()
    if Equipped == true and Cooldown == false then
        UIS.InputBegan:Connect(function(input)
            if input.KeyCode == Enum.KeyCode.R then
                Cooldown = true
                game.ReplicatedStorage.Parry:FireServer()

                controls:Disable()

                print("Player press R")
                wait(3)
                controls:Enable()
                wait(5)

                Cooldown = false

            end
        end)
    end
end

1 answer

Log in to vote
0
Answered by 1 year ago

Hello! Why do you need a loop? Just check if they press R then check if its equipped and cooldown is false.

local UIS = game:GetService("UserInputService")
local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()

local Equipped = false
local Cooldown = false


script.Parent.Equipped:Connect(function()
    Equipped = true
    print(Equipped)
end)

script.Parent.Unequipped:Connect(function()
    Equipped = false
    print(Equipped)
end)

UIS.InputBegan:Connect(function(input)
    if Equipped == true and Cooldown == false then
        if input.KeyCode == Enum.KeyCode.R then
            Cooldown = true
            game.ReplicatedStorage.Parry:FireServer()

            controls:Disable()

            print("Player press R")
            wait(3)
            controls:Enable()
            wait(5)

            Cooldown = false
        end
    end
end)

Hope this helps!

0
Omg i never thought of that, sometimes i just dont think when im scripting, ty! Black_Magic2533 104 — 1y
0
Omg i never thought of that, sometimes i just dont think when im scripting, ty! Black_Magic2533 104 — 1y
0
If this helped, mark it as an answer for other people! LikeableEmmec 470 — 1y
Ad

Answer this question