local DASH_DISTANCE = 20
local DASH_SPEED = 100
local DASH_SLOWDOWN = 5
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local isDashing = false
local function onDash()
if isDashing then
return
end
isDashing = true
local currentVelocity = character.HumanoidRootPart.Velocity
character.HumanoidRootPart.Velocity = character.HumanoidRootPart.CFrame.lookVector * DASH_SPEED
local stopEvent
stopEvent = character.HumanoidRootPart.AncestryChanged:Connect(function(_, parent)
if parent == nil then -- Check if the character is removed from the game
stopEvent:Disconnect()
return
end
if not isDashing then
return
end
local currentSpeed = character.HumanoidRootPart.Velocity.magnitude
character.HumanoidRootPart.Velocity = character.HumanoidRootPart.Velocity * (1 - DASH_SLOWDOWN)
if currentSpeed < 1 then
isDashing = false
end
end)
wait(2)
isDashing = false
script.Parent.MouseButton1Click:Connect(function(onDash)
end)
end
The script does not work when the button is clicked