How do i change the walk animations with a local script?

Ok, I’ve updated the script, don’t forget to modify variables. I do not know if it will work though


i keep getting this. where it does not stop the anim

could you show me in a video

mp4 please

ok

reposting cuz getting annoying scrolling all the way up

--Top Variables (MUST CHANGE)
local animationId = 1

--Main Variables (do not change)
local humanoid = script.Parent:WaitForChild("Humanoid")
local sprinting = false
local CAS = game:GetService("ContextActionService")
local UIS = game:GetService("UserInputService")
local animation = Instance.new("Animation", script)
animation.AnimationId = "rbxassetid://"..tostring(animationId)
animation.Name = "Run"
local track = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
track.Looped = true

--Config (optional changes)
local walkSpeed = 16
local runSpeed = 32
local toggle = true --false if you want to hold sprint
local createButton = false --whether to show button to sprint on mobile devices

----------------------------------------------------------------------------------
function sprint()
if UIS:IsKeyDown(Enum.KeyCode.LeftShift) and UIS:IsKeyDown(Enum.KeyCode.RightShift) then return end
sprinting = not sprinting
if toggle then
if sprinting then
humanoid.WalkSpeed = runSpeed
track:Play()
else
humanoid.WalkSpeed = walkSpeed
end
else
humanoid.WalkSpeed = runSpeed
track:Play()
repeat task.wait(0.1) until UIS:IsKeyDown(Enum.KeyCode.LeftShift) == false and UIS:IsKeyDown(Enum.KeyCode.RightShift) == false
humanoid.WalkSpeed = walkSpeed
sprinting = false
end
end

CAS:BindAction("Sprint", sprint, createButton, Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift)
humanoid.WalkSpeed = walkSpeed

while track ~= nil and sprinting == false and track.IsPlaying do
task.wait()
track:Destroy()
track = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
end

updated (maybe still wont stop anim)

@CaptainTeemukas

nope… is there a way to just swap out the walking animation?

what do you mean by that? just replace the anim?

like change the animation id of the walk anim. while its running.

so while it’s running, change walk anim?

while the animate local script is running’’

Animate script loads
Set walk animation to another ID

the thing is i tried that like a bajilion times

Animate.Walk.WalkAnim.AnimationID = Blah blah.
It still doesnt change

alr, you can delete the script i gave you if you don’t need it anymore

run the game, find your character and copy the animate script

then, exit testing and paste Animate into StarterCharacterScripts

inside the script, change the ids

i did that when i started making the game.i just want to change the animation id in the animate script when holding leftshift

the time i made it work was just making a new animate script and putting it inside the character and deleting the og animate script

swapping out the scripts with a script btw*

local UIS = game:GetService("UserInputService")
local defaultanim = script.Parent:WaitForChild("Animate").run.RunAnim.AnimationId
local humanoid = script.Parent:WaitForChild("Humanoid")

--must change
local animId = 1 --replace this

--optional changes
local runSpeed = 32
local walkSpeed = 16

while task.wait() do
if UIS:IsKeyDown(Enum.KeyCode.LeftShift) or UIS:IsKeyDown(Enum.KeyCode.RightShift) then
script.Parent.Animate.run.RunAnim = "rbxassetid://"..tostring(animId)
humanoid.WalkSpeed = runSpeed
else
script.Parent.Animate.run.RunAnim.AnimationId = defaultanim
humanoid.WalkSpeed = walkSpeed
end
end

i will try it but i need to go. i will tell you if it works or not when im back

1 Like

Roblox’s movement system uses this:
Walk == < 16
Run == >= 16

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