Animation doesn't play, animTrack is a "error-type"

animation is the child of a tool:

this is a local script in the tool:


local tool = script.Parent
local anim = tool:WaitForChild("Animation")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animtrack = humanoid:LoadAnimation(anim)


tool.Activated:Connect(function()
	animtrack:Play()
end)

Perhaps try to load the animation only when the player uses the tool, and load the animation through the Animator object under the Humanoid? (Make sure to also change the animation’s priority to Action)


local tool = script.Parent
local anim = tool:WaitForChild("Animation")


tool.Activated:Connect(function()

    local player = game.Players.LocalPlayer
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:WaitForChild("Humanoid")   
    local animator = humanoid:FindFirstChildOfClass(“Animator”)

   

    local animtrack = animator:LoadAnimation(anim)
	animtrack:Play()
end)

The id of the animation either is invalid or doesn’t exist. Check the assetid of the animation and try again

doesn’t work for startercharacters (sorry for late reply)

Maybe you can try adding the Animator object manually under the StarterCharacter’s humanoid?

it is already in it i tried defining the startercharacter’s humanoid and animator but the animation doesn’t play no errors

Maybe it’s in the animation’s priority? Try setting it to something like Action.

1 Like

i hope you and your familly gets blessed, thank you dude

1 Like

i wanna ask, when i unequip the tool why does the player still have his hands straight like he still equipped the tool? @HelpSupport01

Oops, I overlooked that detail. Let me rewrite my posted script above:


local tool = script.Parent
local anim = tool:WaitForChild("Animation")
local animTrack


tool.Activated:Connect(function()

    local player = game.Players.LocalPlayer
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:WaitForChild("Humanoid")   
    local animator = humanoid:FindFirstChildOfClass(“Animator”)

   

    animtrack = animator:LoadAnimation(anim)
	animtrack:Play()
end)

tool.Unequipped:Connect(function()
   animtrack:Stop()
end)


I think this should work? I don’t have access to my laptop right now

1 Like

it works only if i unequip but not when i destroy the tool and replace it with other

Hi, I’m so sorry for simply typing unchecked scripts! Since I now have my laptop, I was able to actually test my scripts. Make sure to also change the animation’s priority to Action! This should be a final Script:

LocalScript in tool:

local tool = script.Parent
local anim = tool:WaitForChild("Animation")


local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")   
local animator = humanoid:FindFirstChildOfClass("Animator")
local animtrack = animator:LoadAnimation(anim)

local isAnimationPlaying = false -- I'm assuming you don't want animations to be spammed.

tool.Activated:Connect(function()

	if not isAnimationPlaying then
		isAnimationPlaying = true
		animtrack:Play()
		print("Playing animation")
		animtrack.Stopped:Wait()
		isAnimationPlaying = false
	end
end)

tool.Unequipped:Connect(function()
	animtrack:Stop()
end)

LocalScript in ReplicatedFirst:

local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local animator = character:FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator")

character.ChildRemoved:Connect(function(child)
	print("Found removed child")
	if child:IsA("Tool") then

		for i, animation in pairs(animator:GetPlayingAnimationTracks()) do

			if animation.Priority == Enum.AnimationPriority.Action then

				animation:Stop() 

			end 

		end		

	end
end)

can this be used in a flashlight?

Well, any tool that uses an animation when you Activate it should work with these 2 scripts

btw i have creeated a new topic about my flashlight won’t work wanna help in it pls?

I can try! Would you mind to set this reply as the Solution, since my earliest reply didn’t work: