#Trying to make a dash mechanism and animation won't work

1 messages · Page 1 of 1 (latest)

topaz stream
#

The dash works fine, but it looks like I'm walking really fast, here's the script

local UserInputService = game:GetService("UserInputService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "rbxassetid://134453562138268"

local keybind = Enum.KeyCode.LeftControl
local canSlide = true

local dashForce = 100
local dashDuration = 0.3
local dashCooldown = 1

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if not canSlide then return end
if not humanoidRootPart or not humanoid or humanoid.Health <= 0 then return end

if input.KeyCode == keybind then
    canSlide = false

    local animator = humanoid:FindFirstChildOfClass("Animator")
    if not animator then
        animator = Instance.new("Animator")
        animator.Parent = humanoid
    end

    local animationTrack = animator:LoadAnimation(slideAnim)
    local animationWeight = 0.5
    local animationPriority = Enum.AnimationPriority.Action
    animationTrack:Play()

    local slideVelocity = Instance.new("BodyVelocity")
    slideVelocity.MaxForce = Vector3.new(30000, 0, 30000) 
    slideVelocity.Velocity = humanoidRootPart.CFrame.LookVector * dashForce
    slideVelocity.Parent = humanoidRootPart

    task.delay(dashDuration, function()
        if slideVelocity then
            slideVelocity:Destroy()
        end

    end)
    
    task.wait(dashCooldown)
    canSlide = true
end

end)

jolly mesa
#

Put your code around ` so its easier to read

#

or ill do it

#
local UserInputService = game:GetService("UserInputService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "rbxassetid://134453562138268" 

local keybind = Enum.KeyCode.LeftControl
local canSlide = true

local dashForce = 100 
local dashDuration = 0.3 
local dashCooldown = 1

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if gameProcessedEvent then return end 
    if not canSlide then return end
    if not humanoidRootPart or not humanoid or humanoid.Health &lt;= 0 then return end

    if input.KeyCode == keybind then
        canSlide = false

        local animator = humanoid:FindFirstChildOfClass("Animator")
        if not animator then
            animator = Instance.new("Animator")
            animator.Parent = humanoid
        end

        local animationTrack = animator:LoadAnimation(slideAnim)
        local animationWeight = 0.5
        local animationPriority = Enum.AnimationPriority.Action
        animationTrack:Play()

        local slideVelocity = Instance.new("BodyVelocity")
        slideVelocity.MaxForce = Vector3.new(30000, 0, 30000) 
        slideVelocity.Velocity = humanoidRootPart.CFrame.LookVector * dashForce
        slideVelocity.Parent = humanoidRootPart

        task.delay(dashDuration, function()
            if slideVelocity then
                slideVelocity:Destroy()
            end

        end)

        task.wait(dashCooldown)
        canSlide = true
    end
end)