I am making a dash script and successfully did it but the players spams it. i want to fix this but i don't know how to do it.
The Code:
local player = game.Players.LocalPlayer repeat wait() until player.Character.Humanoid```` local humanoid = player.Character.Humanoid local mouse = player:GetMouse() local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=1824890937" mouse.KeyDown:connect(function(key) if string.byte(key) == 50 then local playAnim = humanoid:LoadAnimation(anim) playAnim:Play() script.Sound:Play() player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 125 wait(1.5) end wait(10) end)
Assign the current machine time tick()
to an upvalue (variable in an outer scope), subtract tick()
from that variable and check if it's larger than an arbitrary number.
local lastClicked, cooldown = 0, 2 UserInputService.InputBegan:Connect(function(input, gameProcessed) if tick() - lastClicked >= cooldown then lastClicked = tick() -- ... end end)