Having Trouble in Writting a Script to Run Animations on Humaoinds

I am following a Youtube tutorial and written the code below:

local function animateMob(object)
	local humanoid = object:WaitForChild("Humanoid")
	local animationsFolder = object:WaitForChild("Animations")
	
	if humanoid and animationsFolder then
		local walkAnimation = animationsFolder:WaitForChild("Walk")
		if walkAnimation then
			local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
			local walkTrack = animator:LoadAnimation(walkAnimation)
			walkTrack:Play()
		end
	else
		warn("No humanoid/animation folder for", object.Name)
	end
end

workspace.Mobs.ChildAdded:Connect(animateMob())

But for some reason, the humanoids (Mobs) doesn’t walk following the animations:

Below image shows the position of the script:
image

Sorry if I made a very simple mistake. I am very new in scripting.

You can’t use other people’s animations, you need to make your own.

Hmmm… I don’t get what you’re trying to say?

Gnomecode himself made the animation I suppose, you can’t use animations that are not owned by you ( that you didn’t make the animation ). You have to make your own animation.

Yea ik but I am temporarily using his animations to test out the code of course I will use my own mob and animations after completing the tutorials

…you can’t use other people’s animations, it doesn’t work

What @2kvigilanxe was trying to say is, it is not your respective asset and only you can use your own. That means the owner of the animation asset can only use their own, so as yours.

Ohhh! I misunderstood lol :sweat_smile: :joy: Thank you for ur help. I will try it later.

It doesn’t work, this message came out:

Can you share the entire script? Those lines aren’t in the script you provided above.

I think I copied the whole script in my question

	local humanoid = object:WaitForChild("Humanoid")
	local animationsFolder = object:WaitForChild("Animations")
	
	if humanoid and animationsFolder then
		local walkAnimation = animationsFolder:WaitForChild("Walk")
		if walkAnimation then
			local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
			local walkTrack = animator:LoadAnimation(walkAnimation)
			walkTrack:Play()
		end
	else
		warn("No humanoid/animation folder for", object.Name)
	end
end

workspace.Mobs.ChildAdded:Connect(animateMob())
workspace.Mobs.ChildAdded:Connect(animateMob)

Does the animations folder have animations?

Yes
image

local function animateMob(object)
	local humanoid = object:WaitForChild("Humanoid")
	local animationsFolder = object:WaitForChild("Animations")

	if humanoid and animationsFolder then
		local walkAnimation = animationsFolder:WaitForChild("Walk")
		if walkAnimation then
			local walkTrack = humanoid:LoadAnimation(walkAnimation)
			repeat task.wait() until walkTrack.Length > 0
			walkTrack:Play()
		end
	else
		warn("No humanoid/animation folder for", object.Name)
	end
end

workspace.Mobs.ChildAdded:Connect(animateMob)

It is working! Thank you very much!!! So the problem is this?
repeat task.wait() until walkTrack.Length > 0