Running Animation not Playing

I’m trying to make a CPU that moves around, so the player can mess with it, however, I’m in the middle of playing a run animation when the CPU starts running, and I cannot seem to get it to play. The CPU just moves, but without the animation, and I do not know why this isn’t working.

This is what it looks like.

cpumove

I’ll also provide the script that handles the CPU behavior.

--Variables
local physicsService = game:GetService("PhysicsService")
local dummy = game.ServerStorage.Dummy
local description = dummy.CPUDescription
local spawnPoint = Vector3.new(0, 5, 0)
dummy.Humanoid:ApplyDescription(description)
local runAnim = dummy.Humanoid:LoadAnimation(dummy.RunAnim)

--CPU behavior
while true do
	--Make CPU
	local cpu = dummy:Clone()
	cpu.Parent = game.Workspace
	cpu:MoveTo(spawnPoint)
	local humanoid = cpu.Humanoid
	local root = cpu.HumanoidRootPart
	--Collision
	local dummyParts = cpu:GetDescendants()
	for index, dummyPart in pairs(dummyParts) do
		if dummyPart:IsA("BasePart") then
			physicsService:SetPartCollisionGroup(dummyPart, "Players")
		end
	end
	--Animation (This is where the problem is)
	local running = humanoid.Running:Connect(function(speed)
		if speed > 0 then
			runAnim:Play(10, 01, 10)
		else
			runAnim:Stop(10)
		end
	end)
	--CPU movement
	local movement = coroutine.wrap(function()
		wait(1)
		while true do
			--Make positions
			local pos = root.Position
			local x = math.random(-10, 10)
			local z = math.random(-10, 10)
			local movePos = pos + Vector3.new(x, 0, z)
			humanoid:MoveTo(movePos)
			humanoid.MoveToFinished:Wait()
			wait(2)
			--Break movement if dead
			if humanoid.Health == 0 then
				break
			end
		end
	end)
	movement()
	--Wait until it dies
	cpu.Humanoid.Died:Wait()
	wait(5)
	cpu:Destroy()
	running:Disconnect()
end

No errors appear in the output, so I can evaluate what’s really going on.

  1. What do you want to achieve? I want to create a CPU that moves around freely.

  2. What is the issue? The running animation doesn’t play at all.

  3. What solutions have you tried so far? I had tried searching for other posts, but I found nothing that could help.

To clarify, the running animation is inside the CPU’s model. I have little experience with scripting animations, so I can’t figure this out. I am indeed puzzled.

Maybe try commenting out your core loop and just putting some code at the top to run the animation? That should indicate if the animation isn’t loading entirely for some reason.

1 Like

Putting this after the variables does nothing.

runAnim:Play(1, 1, 1)

And I can’t comment out my code because the code itself clones the CPU into workspace, and if I commented only part of it, it would time out.

It’s probably good for debugging purposes to just only load in the animation on an NPC and then use the :Play: method for starters. That’ll indicate if the animation not loading in is the core problem or not.

If it is related to playing the animation before it finishes loading on the client, I’ve already talked about this issue in the past. The suggestion is still to try some sort of countdown to test if that is the case. Also, humanoid.Running is very inaccurate, my suggestion is to manipulate the animation on RenderStep or another similar interval. I never play NPC movement animations on the server though usually, I do it on the client because that way I can make NPCs that are farther away update slower (or not at all) saving on performance costs, but this really only helps if this is practically the only thing you’re doing every tick/frame for the NPC.

After waiting for 60 seconds before spawning the CPU, but after calling LoadAnimation() on the humanoid, it still doesn’t work, and in your reply in the other post you linked, you suggested to wait for 15 seconds, so I don’t think loading is the problem.

Is the animation ID correct? It should be rbxassetid://ID_HERE or something similar. Check if it imports into the NPC with the animation editor too.
Also try using runAnim:Play(1) and comment out everything from the running to movement().

EDIT:
This is most likely the actual issue after a bit of looking into it:
LoadAnimation creates a new object, so cloning the dummy wouldn’t matter as it still references the old object.
This would be similar to doing

local hum = dummy.Humanoid
local copy = dummy:Clone()
copy.Parent = workspace
hum.Health = 0 

and expecting the dummy clone to die.
Where?

Also, for future reference, use something like this instead:

game:GetService("ServerStorage"):WaitForChild("Dummy")

and similar process when retrieving other objects for the first time.

The id is correct. Only having “1” as a parameter doesn’t work when I comment out what you suggested me to comment out. When I call LoadAnimation() for the clone’s humanoid, nothing changes.

Try doing nothing but this:

local stored = game:GetService("ServerStorage"):WaitForChild("Dummy")
local animation = stored:WaitForChild("Humanoid"):WaitForChild("RunAnim")
local copy, animtrack

copy = stored:Clone()
copy.Parent = workspace
animtrack = copy:WaitForChild("Humanoid"):LoadAnimation(animation)

wait(12)
print("Playing animation")

animtrack:Play(1)

By doing just this, the animation yet again fails to play, after “Playing animation” has been printed.

Try another animation then, like this one. (updated to a Roblox animation)
If this works then your running animation is not loading properly. Try making a new one.
Make sure to use an R15/Rthro rig.

After testing the game three times, the animation fails to load, and errors.

I updated it just now to a Roblox animation, try that one.