Animation not playing after character death

I have an animation play when a player equips a tool. The problem is that when the player resets or dies, the animation won’t play. The error it gives me is,

Cannot load the AnimationClipProvider Service.

Here’s the code

local player = game:GetService("Players")
local Tool = script.Parent
local Animation = Tool.Handle:WaitForChild("holdlaser")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()


Tool.Equipped:Connect(function()
	local hum = char:WaitForChild("Humanoid")

	local anim = hum:LoadAnimation(Animation)

	anim:Play()
	
	Tool.Unequipped:connect(function()
		anim:Stop()

	end)    

end)



This is in a localscript inside the tool. The error happens on line 10.
Any help is appreciated.

1 Like

Try and load the animation on the humanoid’s animator and do it outside of the event.

I found the solution. You have to put the Humanoid and character variable inside the equip and unequip function. So my corrected code would be:

local player = game:GetService("Players")
local tool = script.Parent
local animation = tool.Handle:WaitForChild("holdlaser")
local plr = player.LocalPlayer

tool.Equipped:Connect(function()
	wait()
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	local anim = hum:LoadAnimation(animation)

	anim:Play()
	
	tool.Unequipped:connect(function()
		wait()
		local char = plr.Character or plr.CharacterAdded:Wait()
		local hum = char:WaitForChild("Humanoid")

		anim:Stop()

	end)    

end)



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