Question about sprint toggles

I have always wanted to make a sprint toggle that changed the walk animation to a sprinting animation, but it never worked… and i dont know how to make one because ive never found advice or a tutorial for it, A universal times sprint toggle for example, the game has a shift to toggle sprint button that changes the walkspeed and the walk animation

1 Like
  1. either use userinputservice or contextactionservice to detect device input or changes
    2.You need a animationid for sprinting that you can change the default walk animation
1 Like

well i do have the animation id, i know how the userinputservice works, i just have no idea how to do this

First do you know how to make a a shift sprint or in this case a toggle sprint to change a player characters speed

that i do, i also know how to make a hold shift to sprint thingy, but im looking for a toggle

the toggle thing is it a button ui that you activate

i want to make a it a keycode button, like Q, or any other key

k so you want it to be able to toggle on and off

yes, walk and sprint

when toggled to sprint the animation is set to the sprinting animation, and set to the walking animation when toggled to walk

have you thought of using a boolean to detect whether they are sprinting or walking when you trigger the key

localscript located in startercharscripts

local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local sprinting = false

game.UserInputService.InputBegan:Connect(function(gpe, io)
    if not gpe and io.KeyCode == Enum.KeyCode.Q then
        if not sprinting then
            sprinting = true
            -- play animation, change walkspeed
        elseif sprinting then
            sprinting = false
            -- stop animation, chang walkspeed back to game.StarterPlayer.CharacterWalkspeed
        end
    end
end

something like this

1 Like

As @whiplash3r mentioned pretty much like that

1 Like

i have tried, but it was really buggy and stuff, cause i tried playing the sprinting animation instead of changing it but it just made the animation break (i dont know how to do the change thing properly)

or would it be better to just play it?

have you set its priority to action the Animatiion

i have tried that before, this was the result

the character did not stop playing the animation

1 Like

Have you tried Adjusting its speed the animation

1 Like

provide code please.

30 letter minimum

1 Like
local Character:Model? = script.Parent
local Humanoid:Humanoid? = Character:WaitForChild("Humanoid")
local Animator:Animator? = Humanoid:WaitForChild("Animator")

local Animation = script.Animation
local SprintAnimation = Animator:LoadAnimation(Animation)
local IsSprinting = script.IsSprinting

IsSprinting.Changed:Connect(function(Value)
    if Value then
        SprintAnimation:play()
        Humanoid.WalkSpeed = 24
    else
        Humanoid.WalkSpeed = 16
        SprintAnimation:Stop()
    end
end)
UIS.InputBegan:Connect(function(Input,GPE)
    if GPE then return end
    if Input.KeyCode == Enum.KeyCode.Q then
        IsSprinting.Value = not IsSprinting.Value
    end
end)
1 Like

this was my best attempt
at it