Animations with R6 Rigs

I’m trying to get an animation to play on an R6 player, I followed a tutorial but the animation does not play but the rest of the things in the script work, anybody know who to fix this? I have tried using other animations than the one they use in the video.
Script:

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

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 35
		local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://6712401177'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim:Play()
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 16
		PlayAnim:Stop()
	end
end)

Any help is appreciated! :slight_smile:

2 Likes

Humanoid:LoadAnimation() is a deprecated(removed) use the Animator instead (Humanoid:WaitForChild("Animator"):LoadAnimation([Animation Instance])) .
In your case, the animation instance would be the variable named Anim.

Are you sure you are loading an animation that is in your inventory? You can only run animations you own for safety reasons.

Didn’t work, nothing changed, no errors or anything, and the code after it still runs.

Though I’m not sure if I did it right, all I did was change 1 line to be this

PlayAnim = Character.Humanoid:WaitForChild("Animator"):LoadAnimation(Anim)

I can’t seem to replicate the issue, are you sure the animation is in your inventory? And where is the script located?

The script is inside the player’s character and I’m using an animation that I made.

What’s the priority of the animation? If the priority is set too low it won’t be able to play over the default walking animation.

How might I set priority? I tried setting it like this but nothing changed:

PlayAnim = Character.Humanoid:WaitForChild("Animator"):LoadAnimation(Anim)
PlayAnim.Priority = 1000
PlayAnim:Play()

Here’s a link to the wiki: AnimationTrack | Roblox Creator Documentation

I’d set the priority within the animation editor

I looked at the animation you’re trying to use, it’s uploaded by someone else. Assuming the account you’re using is the one you’re using to communicate here then, you have to have uploaded the animation yourself. You’re unable to use other users animations unless it’s uploaded by ROBLOX themselves.

I’m using a different one, that’s just the one from the tutorial.

I set it to action but the default run animation still plays over it. I used Enum.AnimationPriority.Action

How exactly did you adjust the priority? Through script or through the animation editor?

I tried in script with:

PlayAnim = Character.Humanoid:WaitForChild("Animator"):LoadAnimation(Anim)
PlayAnim.Priority = Enum.AnimationPriority.Action
PlayAnim:Play()

and I also attempted to do it in animation editor and that didn’t work either.

What does it say when you try printing the animation priority before/after you play it?

It says the priority is action both times. (before and after)

Have you also confirmed by script that the animation’s actually playing and the length of it isn’t 0 seconds?

I did

print(PlayAnim.Length)

and it said 0 so how might I fix that?

You can try preloading the animation, instead of making a new animation every time the player starts running. Something like:

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

local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://YOUR_ID'
local PlayAnim = Character.Humanoid:WaitForChild("Animator"):LoadAnimation(Anim)

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

		PlayAnim:Play()
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 16
		PlayAnim:Stop()
	end
end)