#Shift to sprint with animation not working

1 messages · Page 1 of 1 (latest)

mellow sand
#

trying to make it so that when you press shift you sprint and it runs the sprint animation, the speed increases but animation wont play
I have this in statercharacterscripts

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local BaseSpeed = 16
local SprintSpeed = 30
local sprintAnim = "rbxassetid://140391691616690"

local function setupCharacter(character)
    local Humanoid = character:WaitForChild("Humanoid")
    local AnimateScript = character:WaitForChild("Animate")

    local normalRunAnim = AnimateScript.run.RunAnim.AnimationId

    local function startSprint()
        Humanoid.WalkSpeed = SprintSpeed
        AnimateScript.run.RunAnim.AnimationId = sprintAnim
    end

    local function stopSprint()
        Humanoid.WalkSpeed = BaseSpeed
        AnimateScript.run.RunAnim.AnimationId = normalRunAnim
    end

    UserInputService.InputBegan:Connect(function(input, gameProcessed)
        if gameProcessed then return end
        if input.KeyCode == Enum.KeyCode.LeftShift then
            startSprint()
        end
    end)

    UserInputService.InputEnded:Connect(function(input, gameProcessed)
        if input.KeyCode == Enum.KeyCode.LeftShift then
            stopSprint()
        end
    end)

    Humanoid.Died:Connect(function()
        stopSprint()
    end)
end

Player.CharacterAdded:Connect(setupCharacter)
if Player.Character then
    setupCharacter(Player.Character)
end
agile trout
# mellow sand trying to make it so that when you press shift you sprint and it runs the sprint...

the default Animate script preloads all the animations and doesnt recheck the ids after
you need to manually load the animation and play it
you can get the Animator from under the player's Humanoid
https://create.roblox.com/docs/reference/engine/classes/Animator#LoadAnimation
https://create.roblox.com/docs/reference/engine/classes/AnimationTrack#Play
i suggest loading both at the top of the script and not loading them every time you want to play as it will cause delays and reach a hard limit

mellow sand
#

@agile trout I cant seem to figure out how to do that could you show me how I would manually load it

velvet glacier
#

This straight up looks like ai code

#

To me

mellow sand
#

all gotta start somewhere ;-;

velvet glacier
#

Like I literally don't understand this script

mellow sand
#

I ended up just deleting it and making a new one

covert pendantBOT
#

studio** You are now Level 1! **studio

mellow sand
velvet glacier
#

I can tell you what you should write instead if u still need help

mellow sand
#

@velvet glacier could you tell me a good way to learn concepts that you don't understand cause I feel like ive just been memorizing how to do things instead of actually knwoing what they do

velvet glacier
#

Experimenting, failing then learning from your mistakes is the best way to learn.