Rig won't play animation

This is a relatively simple problem, so I don’t think I need too much context.

Code, it is ran on server.

image

The animation id is the animation, the Animator, i haven’t touched at all.

code

local function playAnimationFromServer(character, animation)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		-- need to use animation object for server access
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if animator then
			local animationTrack = animator:LoadAnimation(animation)
			animationTrack:Play()
			return animationTrack
		end
	end
end

script.Parent.Touched:Connect(playAnimationFromServer)

This is all inside of a regular Block rig I put in.

2 Likes

You don’t seem to be applying the character and animation variables in the function.

2 Likes

As @krasycheckz correctly said, you aren’t providing the correct parameters to the playAnimationFromServer function. The only parameter which will be automatically passed is hit which is the part which interacted with script.Parent. Instead you should make sure the part is a character part and pass the character and animation to the function:

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://your_animation_id"

script.Parent.Touched:Connect(function(hit)
	--to ignore npcs, replace the condition with game.Players:GetPlayerFromCharacter(hit.Parent)
	if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
		playerAnimationFromServer(hit.Parent, animation)
	end
end)
3 Likes

I rewrote the code (Based on what I had earlier) and this is what my rig looks like.

image

Code:

local character = script.Parent
local animation

local humanoid = script.Parent.Humanoid
if humanoid then
	-- need to use animation object for server access
	local animator = humanoid:FindFirstChildOfClass("Animator")
	if animator then
		local animationTrack = animator:LoadAnimation(script.Parent.Humanoid.Animation)
		animationTrack:Play()
		return animationTrack
	end
end

So did you figure it out and made it work? I Have a similar problem and i can’t find a solution