Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

4 comments

0

wait let me edit it

0

You disabled the script buddy; it's not going to continue executing LOL.

0

Use a boolean debounce instead.

0

whats that?

1 answer

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

2 comments

0

wait when will it make the script disable? (sorry if I have bad english)

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

This discussion is preserved as it was. New answers, comments, and votes are closed.