Animation wouldnt play in a viewmodel

help! my local script wouldnt play the animation in the viewmodel even though its outputting the text that i created

local animationwalk = script:WaitForChild("walk")
local arm = game.ReplicatedStorage.viewmodel.RightArm
local viewhuman = game.ReplicatedStorage.viewmodel.Humanoid
local realhuman = script.Parent:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")

local walking = viewhuman:LoadAnimation(animationwalk)

print("Walking Animation Loaded:", walking)


realhuman.Running:Connect(function(movementSpeed)
	print("Movement Speed:", movementSpeed)
	if movementSpeed > 0 then
		if not walking.IsPlaying then
			print("Starting Walking Animation")
			walking:Play()
		end
	else
		if walking.IsPlaying then
			print("Stopping Walking Animation")
			walking:Stop()
		end
	end
end)


for i = 1, 5 do
	print(i)
	wait(0.5)
	if i == 5 then
		print("horray!")
	end
end

it outputs but not playing the animations for the viewmodel

Two things which may help;

  1. I’d use an Animator class for your view-model, reasoning for doing so is explained here. Just pop it under your view-model’s Humanoid and load animations using that instead.

  2. Check and make sure only one part in your view-model is anchored, such as the Head or HumanoidRootPart.

Hello,

Even if I played the animation using animator instead, it’s still not working
(iam an absolute beginner in developing btw so im sorry if im not smart, im 4 months in dev of my first game) but I’m going to give you some info about the like, thing

The ViewModel is a mesh part that maybe the problem but I’m not sure about that.

The Animation is in R6 and the humanoid of the ViewModel is R6 so It’s compatible but again it maybe because the viewmodel is an mesh part

That’s really all the info that I, may know.

Upated Code:

local animationwalk = game.ReplicatedStorage.viewmodel.walk

local viewhuman = game.ReplicatedStorage.viewmodel.Humanoid.Animator
local realhuman = script.Parent:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")
local walking = viewhuman:LoadAnimation(animationwalk)

print("Walking Animation Loaded:", walking)

-- Connect to the Running event of the player's Humanoid
realhuman.Running:Connect(function(movementSpeed)
	print("Movement Speed:", movementSpeed)

	-- Check if the player is moving
	if movementSpeed > 0 then
		-- Check if the animation is not already playing
		if not walking.IsPlaying then
			print("Starting Walking Animation")
			walking:Play()
		end
	else
		-- Check if the animation is currently playing
		if walking.IsPlaying then
			print("Stopping Walking Animation")
			walking:Stop()
		end
	end
end)

-- A loop to demonstrate the script is running
for i = 1, 5 do
	print(i)
	wait(0.5)
	if i == 5 then
		print("hooray!")
	end
end

i forgot to also include this but anyways i updated the viewmodel but it still wouldnt work so yeah

Are you trying to play an animation inside ReplicatedStorage?

trying to play a animation inside in the view model

But it looks like the viewmodel is inside ReplicatedStorage

it is in replicated storage

now i could have a new parent which inside in the script

(what i mean is the animation)

I finally fixed my bug, i look into it and some script is the culprit, thank you hapun for pointing out the animator thing, though its not the problem, the blog post is very informational so thank you.

2 Likes

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