this script is a dash script, double tap W and you will dash. nothing is wrong with it except the local cd is supossed to act as a 5 seconds cooldown. the bad thing is it doesnt. why doesnt it work?
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local Tapped = false
local cd = false
if cd == false then
cd = true
UserInputService.InputBegan:Connect(function(Input, GameStuff)
if GameStuff then return end
if Input.KeyCode == Enum.KeyCode.W then
if not Tapped then
Tapped = true
wait(0.3)
Tapped = false
else
Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector*330
local Animation = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(script.Animation)
Animation:Play()
wait(5)
cd = false
end
end
end)
end
You do not seem to be altering the Var Gamestuff, which when set to false prevents the player from sprinting I think.
I could be wrong, I am trying to see if there is anything else in the script I missed
I think its because that script only functioned 1 time, so I think when you press the key and you check the cd value will be much better
-- maybe this?
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local Tapped = false
local cd = false
UserInputService.InputBegan:Connect(function(Input, GameStuff)
if cd == false then
cd = true
if GameStuff then return end
if Input.KeyCode == Enum.KeyCode.W then
if not Tapped then
Tapped = true
wait(0.3)
Tapped = false
else
Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector*330
local Animation = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(script.Animation)
Animation:Play()
wait(5)
cd = false
end
end
end
end)
Seems like I’m a bit late, but a better way of keeping track of when the player pressed ‘W’ would be using os.clock()
local UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local debounce = false
local lastTime = os.clock()
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed or debounce then
return
end
if os.clock() - lastTime < 0.3 then — time between taps
debounce = true
— dash code
wait(2) — cooldown
debounce = false
end
lastTime = os.clock() — reset timer
end)