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
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!