How do I make a Toggle Sprint with animation

I tried for a while to make a regular sprint with animation, but I could never get it right.

So instead I tried to make a sprint that only starts once someone presses left control and goes infinitely until they press it again.

And I wanted the animation to only start when they are moving, but of course I failed.

How do I do this?

8 Likes
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character

UIS.InputBegan:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftControl then
  Character.Humanoid.WalkSpeed = 35
         end
end)

I’ve tried things like this for starters.

2 Likes

If you want to do the animation, you can simply play in Studio, go to your character and copy the “Animate” LocalScript, stop the game and paste that script into StarterCharacterScripts, after you can change the Running animation value to your running animation ID, and you’ll be set.

1 Like

I have done that to change the idle and the run animation but I don’t straight up want it to be “infinite sprint” I want a toggle

1 Like

Do you want them to sprint while holding left control? Or do you want them to sprint once its pressed, and if pressed again, it will stop sprinting?

1 Like

Press it then press it again to stop

1 Like

local IsRunning = false
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
IsRunning = not IsRunning
if IsRunning == true then
Character.Humanoid.WalkSpeed = 35
else
Character.Humanoid.WalkSpeed = 15
end
end
end)

11 Likes

Thank you, but for the animation I thought I could simply change the default run animation to a new one. But as always it’s never that simple and didn’t work.

1 Like

It should work since roblox changes the HumanoidStateType from Running to Walking depending on WalkSpeed, and uses the appropriate animation.

You’re welcome!

3 Likes

We have a problem, I can’t change the run animation…

(Or my tiny peanut brain doesn’t know how to)

I think it’s different to change from all the other ones

1 Like
script.Parent.Animate.run.RunAnim.AnimationId = ("rbxassetid://5362333091")

This is the script I used to try to change it that works for other animations

1 Like

No.
So what you do is, press Play, go to your character and copy the “Animate” script
End game, then paste the script into StarterPlayer>StarterCharacterScripts
Expand the script and look for “run” expand that and then you will see “RunAnim” change the AnimationId to your animation.

2 Likes

I did and its still the default

1 Like

Check if there was any errors loading the Animation?

2 Likes
{ id = "run.xml", weight = 10 } 

thats what it says inside the animate script

1 Like

replace that with
{ id = “YourAnimationId”, weight = 10 }

2 Likes

still the default one :confused:

30char

1 Like

Whenever I change the walk animation it works but run never changes

1 Like

You can change the weight of the running animation on the script.

2 Likes

what does that do?

30 characters

1 Like