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

My cooldown keeps getting bypassed?

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

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!

3 comments

0

Omg i never thought of that, sometimes i just dont think when im scripting, ty!

0

Omg i never thought of that, sometimes i just dont think when im scripting, ty!

0

If this helped, mark it as an answer for other people!

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