Issues playing animation

I would like to play an animation so that everyone can see it, the animation is running but I want it to play in a ‘loop’ way when I press the W key, what am I doing wrong?

local runAnimation = script.Parent.runAnim

local runAnimationTrack = humanoid:LoadAnimation(runAnimation) 

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		-- Play anim
		runAnimation:Play()
	end
end)

What exactly is the error it shows?

Oh sorry, I was wrong, **there's no error is shown in output I just updated the post with more details

Oh :sweat_smile:
Well I think you need to set the animation to loop in the animation editor and then you’ll also need to check when the input ends too so that you can stop the animation.
image

Something like this? the problem is that it’s not playing the animation :frowning:

local runAnimation = script.Parent.runAnim

local runAnimationTrack = humanoid:LoadAnimation(runAnimation) 

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		-- Play anim
		runAnimation:Play()
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		-- Play anim
		runAnimation:Stop()
	end
end)

Ah yes, I see the issue. Unfortunately Humanoid | Roblox Creator Documentation was deprecated so you’ll need to use the newer Animator | Roblox Creator Documentation instead - it works in pretty much the same way from what I can tell when I’ve used it.

2 Likes

Humanoid:LoadAnimation still works, its not deprecated

I just did it but the animation does not play, it does not show the print either

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild("Humanoid")

local animator = humanoid:FindFirstChildOfClass("Animator")
local animationId = script.Parent.runAnim.AnimationId
local animationTrack = animator:LoadAnimation(animationId)

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		if animator then
			local playAnim = animationTrack
			playAnim:Play()
			print('playing animation')
			return playAnim
		end
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		if animator then
			local playAnim = animationTrack
			playAnim:Play()
			print('stop animation')
			return playAnim
		end
	end
end)

and got an error:

local runAnimation = script.Parent.runAnim

local runAnimationTrack = humanoid.Animator:LoadAnimation(runAnimation) 
runAnimationTrack.Looped = true
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		-- Play anim
		runAnimation:Play()
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		-- Stop anim
		runAnimation:Stop()
	end
end)

Edit: forgot to add the script box lol

2 Likes

got an error :frowning:

image

whoops I used the wrong variable

local runAnimation = script.Parent.runAnim

local runAnimationTrack = humanoid.Animator:LoadAnimation(runAnimation) 
runAnimationTrack.Looped = true
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		-- Play anim
		runAnimationTrack:Play()
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		-- Stop anim
		runAnimationTrack:Stop()
	end
end)

First of all you would put the animationId into the actual animation instance then you would use the
LoadAnimation() function on the humanoid with a colon infront of it and the whole animation in the parameter

Loading animations on the humanoid is deprecated:

Thats funny though it works for me fine

Just cuz it works fine doesn’t mean it isn’t deprecated. You can still use deprecated functions, just they won’t work as well as the alternative.

I mean it is… use your eyes man

Somthing along The lines of this should work

Alr sorry I didnt know it was deprecated just always worked flawless for me

You don’t need to redefine the animation. my code should work a bit better

Thank you so much guys! it is working perfect! :smiley: thank you for your comments they were very helpful