How can I add a Dash function?

Hi everyone I’m currently working on an Ability Tool Dash System ig. And now I just need a function that moves the Player without running towards when the tool is activated here is the script(I just need the Dash function.

local tool = script.Parent
local handle = tool:WaitForChild(“Handle”)
local sound = handle:WaitForChild(“SwordSlash”)

local debounce = false

tool.Activated:Connect(function()
if not debounce then
debounce = true
sound:Play()
wait(5) – change to whatever you want
debounce = false
end
end)

2 Likes

You could try tweening the HumanoidRootPart, just bare in mind you might need to raycast to make sure they don’t go through walls.

local ts = game:GetService("TweenService")
local info = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

ts:Create(HumanoidRootPart, info, {CFrame = CFrame.new(HumanoidRootPart.CFrame.Position + (HumanoidRootPart.CFrame.LookVector * 10)) * CFrame.Angles(HumanoidRootPart.CFrame:ToEularAnglesXYZ())})
1 Like

Instead of tweening the Position, we can directly modify the Velocity like this:

-- Roblox Services
local RunService = game:GetService("RunService")

-- Object References
local tool = script.Parent

-- Variables
local currentlyDashing = false
local dashConnection = nil

-- Constants
local DASH_POWER = 60
local DASH_DURATION = 0.5
local DASH_COOLDOWN = 5

-- Events
tool.Activated:Connect(function()
    local character = tool.Parent
    local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
    
    if currentlyDashing or not humanoidRootPart then
        return
    end

    currentlyDashing = true

    local lookVector = humanoidRootPart.CFrame.LookVector
    local unitVector = Vector3.new(lookVector.X, 0, lookVector.Z).Unit
    local startTime = os.clock()
    local alpha = 0

    dashConnection = RunService.Stepped:Connect(function()
        alpha = math.min((os.clock() - startTime) / 0.5, 1)
        local exponentialOutValue = alpha == 1 and 1 or 1 - math.pow(2, -10 * alpha)
        local velocity = unitVector * DASH_POWER * exponentialOutValue
        humanoidRootPart.AssemblyLinearVelocity = Vector3.new(velocity.X, 0, velocity.Z)
    end)

    task.wait(DASH_DURATION)
    dashConnection:Disconnect()

    task.wait(DASH_COOLDOWN)
    currentlyDashing = false
end)
6 Likes

It works thx you both thx thx thx

I just found 1 small problem when I click on for the first time it wrks but if I click more than once it reacts after I click a second time

That’s because there’s a cooldown, if you don’t want the cooldown you can lower it or remove it by modifying the DASH_COOLDOWN value, it is reflected in seconds.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.