Problem with animation

Hello devforum, I need some help with this script.

The animation works well, but when it tries to play the animation again after the player has died it shows this: image

This is the script:

local animation

animOnEvent.OnServerEvent:Connect(function(plr, anim, hum)
	if hum ~= nil then
		animation = hum:LoadAnimation(anim)
		animation:Play()
	end
end)

animOffEvent.OnServerEvent:Connect(function(plr, anim, hum)
	if animation ~= nil then
		animation:Stop()
	end
end)

The humanoid your are passing to the function most likely doesn’t exist anymore. I recommend making a variable for the humanoid inside the function itself. Also I don’t think you can pass instances through remotes, they output as nil.

3 Likes