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

My run scripts cooldown is always failing after it works for the 1st time working how do I fix it?

Asked by 3 years ago
Edited 3 years ago
if script.Parent.Disabled == true then
    wait(5)
    script.Parent.Disabled = false
    wait(0)
    script.Parent.Disabled = true

my script

game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        for i = 1,16 do
            wait()
            game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed + 1
        end
    end
end)

game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        for i = 1,16 do
            wait()
            game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed - 1
        end
    end
end)

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function()
    game.Workspace.Camera.FieldOfView = 70
    game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
    script.Disabled = true
end)

and the script I am trying to cool down (I stole it from someone as that was at times I did not know how to code)

0
wait let me edit it ElderRaider2353236 0 — 3y
0
You disabled the script buddy; it's not going to continue executing LOL. Ziffixture 6913 — 3y
0
Use a boolean debounce instead. Ziffixture 6913 — 3y
0
whats that? ElderRaider2353236 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

If you want a cooldown you should probably use a debounce variable instead of disabling the script, as that stops the thread completely..

if debounce == true then
    wait(5)
    debunce = false
    wait(0)
    debounce = true
end
0
wait when will it make the script disable? (sorry if I have bad english) ElderRaider2353236 0 — 3y
0
It doesn't disable the script but it checks if debounce == true, then wait(5) before making it false. If you disable the script then none of this will run, which is why a debounce is better to use. if youre still confused: https://developer.roblox.com/en-us/articles/Debounce Omq_ItzJasmin 666 — 3y
Ad

Answer this question