Why won't the animation play?

Im trying to play this animation of a viewmodel with a humanoid and an animator.

The animation just doesnt play for sum reason

Heres the code

-- Load the walking animation
local replicatedStorage = game:GetService("ReplicatedStorage")
local viewModel = replicatedStorage:WaitForChild("ViewModel")
print("ViewModel found")

-- Ensure the viewmodel has a Humanoid
local humanoid = viewModel:FindFirstChild("Humanoid")
if not humanoid then
	print("No Humanoid found in ViewModel")
	return
end
print("Humanoid found in ViewModel")

-- Ensure the Humanoid has an Animator
local animator = humanoid:FindFirstChildOfClass("Animator")
if not animator then
	animator = Instance.new("Animator")
	animator.Parent = humanoid
	print("Animator added to Humanoid")
else
	print("Animator already exists in Humanoid")
end

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://133960319686107"
local animationTrack = animator:LoadAnimation(animation)
print("Animation loaded")

humanoid.Running:Connect(function(speed)
	print("Running event triggered with speed:", speed)
	if speed > 0 then
		if not animationTrack.IsPlaying then
			animationTrack:Play()
			print("Animation playing")
		end
	else
		if animationTrack.IsPlaying then
			animationTrack:Stop()
			print("Animation stopped")
		end
	end
end)
animationTrack.Stopped:Connect(function()
	print("Animation track stopped")
end)

Output when starting the game:
image

So everything is loading and the script knows it exists but it still doesnt play.

Output when walking is nothing.

Is this ment to play when the character walks?

2 Likes

yes, it should u can see it by this line humanoid.Running:Connect(function(speed)
print(“Running event triggered with speed:”, speed)
if speed > 0 then

1 Like

Why don’t you connect with the script that’s already in the player made by roblox and set the animation to the run animation?

1 Like

can you do it with things different than the player bc its a viewmodel animation not a walking anim

1 Like

Like for an npc?? Sorry never heard of a viewmodel?

1 Like

its like a hand model for guns so you can have longer arms and some accesories to it

1 Like

Well the script stops the animation when the animation plays

1 Like

Ill try fixing it and let u know if it worked

1 Like

Alright, You can try to check when the animation has finished and then stop the animation if you are wondering how to do that if you put a animation id into a animation instance you should be able to see the length

1 Like

Playing animations in a viewport frame requires a WorldModel. Make a WorldModel in your viewport frame, then parent the character you want to animate to the WorldModel.

1 Like

My viewmodel doesnt have a viewport frame tho. It just gets the cameras position and goes there

1 Like