Animation track does not exist (it does actually. SOLVED!)

  1. What do you want to achieve? i wanna play the tower animations

  2. What is the issue? i get the warning that anim track does not exists but it does
    Captura de pantalla 2024-05-21 223648

  3. What solutions have you tried so far? I tried to fix and tried to look for mistakes but there was none for me

local function setAnimation(object, animName)
	local humanoid = object:WaitForChild("Humanoid")
	local MobAnimationsFolder = object:FindFirstChild("Animations")
	local TowerAnimationsFolder = nil

	-- Check if the object is a tower and has an Upgrades folder
	if object:FindFirstChild("Upgrades") and object:FindFirstChild("Level") then
		TowerAnimationsFolder = object.Upgrades[object.Level.Value]:FindFirstChild("Animations")
	end

	if humanoid and MobAnimationsFolder then
		-- Check if the animation exists in the MobAnimationsFolder
		local MobAnimationObject = MobAnimationsFolder:FindFirstChild(animName)

		if humanoid and TowerAnimationsFolder then
			-- Check if the animation exists in the TowerAnimationsFolder
			local TowerAnimationObject = TowerAnimationsFolder:FindFirstChild(animName)

			if TowerAnimationObject then
				local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)

				local playingTracks = animator:GetPlayingAnimationTracks()
				for i, track in ipairs(playingTracks) do
					if track.Name == animName then
						return track
					end
				end

				local AnimationTrack = animator:LoadAnimation(TowerAnimationObject)
				return AnimationTrack
			end
		elseif MobAnimationObject then
			-- If it's a mob and only MobAnimationObject exists
			local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)

			local playingTracks = animator:GetPlayingAnimationTracks()
			for i, track in ipairs(playingTracks) do
				if track.Name == animName then
					return track
				end
			end

			local AnimationTrack = animator:LoadAnimation(MobAnimationObject)
			return AnimationTrack
		end
	end
end

local function playAnimation(object, animName)
	local AnimationTrack = setAnimation(object, animName)

	if AnimationTrack then
		AnimationTrack:Play()
	else
		warn("Animation track does not exists..")
	end
end

Information:
Captura de pantalla 2024-05-21 223538
PLEASE HELP MY WHOLE GAME IS BUGGED BECAUSE OF THIS

On the line before you return the animation track, add some prints. make sure the tower animation object is valid, the animation track is valid, the code reaches that point, etc.

1 Like

i made some prints in it like if not TowerAnimationObject then it prints that is nil, soooo i got in the output that TowerAnimationObject is nil i don’t know why it’s nil. (Adding prints helped me a lot, i found the error and i fixed it)

1 Like

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