Getting an animation error

Hello, on my TD placing system I am getting an error saying “Cannot load the animation clip service”. I don’t know if this is an issue because I am playing the animation on runservice or its a roblox bug. I am trying to play an animation while the unit is in the position of the mouse, but it doesnt play the idle animation and gives me the error

My code:

local function ifCanPlace(self, player: Player, name)
	local animateScript = ReplicatedStorage.AnimateScript.Animate:Clone()
	local camera = workspace.CurrentCamera

	if currentUnitName == name and unitPlaceHolder then
		unitPlaceHolder:Destroy()
		unitPlaceHolder = nil
		currentUnitName = nil  
		if connection then
			connection:Disconnect()
			connection = nil
		end
		if sizeConnection then
			sizeConnection:Disconnect()
			sizeConnection = nil
		end
		rotationAngle = 0
		return
	end

	currentUnitName = name  

	local towerExists = ReplicatedStorage.Units:FindFirstChild(name)
	if not towerExists then
		print("Tower doesn't exist")
		if connection then
			connection:Disconnect()
			connection = nil
		end
		if sizeConnection then
			sizeConnection:Disconnect()
			sizeConnection = nil
		end
		return
	end

	print("Placing unit " .. name)

	if unitPlaceHolder then
		if sizeConnection then
			sizeConnection:Disconnect()
			sizeConnection = nil
		end
		unitPlaceHolder:Destroy()
		unitPlaceHolder = nil
	end

	unitPlaceHolder = towerExists:Clone()
	local circlePart = unitPlaceHolder:FindFirstChild("Circlepart")
	if circlePart then
		local weld = Instance.new("Weld")
		weld.Part0 = circlePart
		weld.Part1 = unitPlaceHolder:FindFirstChild("HumanoidRootPart")
		weld.C0 = CFrame.new(0, 1.85, 0) 
		weld.Parent = circlePart
	end

	local highlight = Instance.new("Highlight")
	highlight.Adornee = unitPlaceHolder
	highlight.Parent = unitPlaceHolder  
	highlight.DepthMode = Enum.HighlightDepthMode.Occluded
	highlight.FillColor = Color3.fromRGB(255, 242, 248)
	highlight.FillTransparency = 0.9
	highlight.OutlineColor = Color3.fromRGB(255, 249, 252)
	highlight.OutlineTransparency = 0.3

	local elapsed = 0
	local duration = 0.18
	local currentScale = 0
	local targetScale = 1.1

	local function lerp(start, goal, alpha)
		return start + (goal - start) * alpha
	end

	sizeConnection = RunService.Heartbeat:Connect(function(deltaTime)
		if unitPlaceHolder then
			unitPlaceHolder.Parent = game.Workspace
			elapsed += deltaTime

			local value = TweenService:GetValue(math.min(elapsed / duration, 1), Enum.EasingStyle.Sine, Enum.EasingDirection.In)

			if unitPlaceHolder then
				unitPlaceHolder:ScaleTo(lerp(currentScale, targetScale, value))
			end

			if elapsed >= duration and sizeConnection then
				sizeConnection:Disconnect()
				sizeConnection = nil
			end
		else
			return
		end
	end)

	for _, part in pairs(unitPlaceHolder:GetDescendants()) do
		if part:IsA("BasePart") then
			part.CollisionGroup = "Unit"
		end
	end

	local appearVFX = unitPlaceHolder:FindFirstChild("Torso").AppearVFX.Gradient :: ParticleEmitter
	appearVFX.Enabled = false
	
	local animator = unitPlaceHolder:WaitForChild("Humanoid").Animator

	local function createAnimationTrack(animId): AnimationTrack
		local anim = Instance.new("Animation")
		anim.AnimationId = animId
		return animator:LoadAnimation(anim)
	end
	
	local idleTrack = createAnimationTrack("rbxassetid://18901619891")

	local function updateTowerPosition()
		if not unitPlaceHolder then
			return
		end
		local mousePosition = UserInputService:GetMouseLocation()
		local mouseRay = camera:ViewportPointToRay(mousePosition.X, mousePosition.Y)
		local raycastParams = RaycastParams.new()
		raycastParams.FilterType = Enum.RaycastFilterType.Exclude
		raycastParams.FilterDescendantsInstances = {unitPlaceHolder, player.Character}

		local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, raycastParams)

		if raycastResult and raycastResult.Instance then
			local hitInstance = raycastResult.Instance
			local hitCharacter = hitInstance:FindFirstAncestorOfClass("Model")

			local x = raycastResult.Position.X
			local y = raycastResult.Position.Y + 4.6
			local z = raycastResult.Position.Z

			local cframe = CFrame.new(x, y, z) 
			idleTrack:Play()
			unitPlaceHolder:SetPrimaryPartCFrame(cframe)    
			return x, y, z
		end
	end

	UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
		if not unitPlaceHolder then
			return
		end
		if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.R then
			if unitPlaceHolder then
				print("Rotating")
				local x, y, z = updateTowerPosition()
				rotationAngle = (rotationAngle + 90) % 360
				local combinedCFrame = CFrame.new(x, y, z) * CFrame.Angles(0, math.rad(rotationAngle), 0)
				unitPlaceHolder:SetPrimaryPartCFrame(combinedCFrame)
			end
		end
	end)


	if connection then
		connection:Disconnect()
		connection = nil
	end

	connection = RunService.RenderStepped:Connect(function(deltaTime)
		if towerExists then
			updateTowerPosition()
		end
	end)
end

Error:

This is weird, have you tried using `:WaitForChild(“Animator”) before playing the animation so the animator is fully loaded and then played? Try something like:

local humanoid = unitPlaceHolder:FindFirstChild("Humanoid")
local animator = humanoid and humanoid:FindFirstChild("Animator")

if humanoid and animator then
    print("Humanoid and Animator found")
else
    if not humanoid then
        print("Humanoid not found")
    end
    
    if not animator then
        print("Animator not found")
    end
end

Try it and then tell me what it outputs.

The script does identify that both instances exist.

What about the services? I noticed that in your shared script, you didnt seem to define any of the services that your using in the script. I.E: RunService, TweenService, ReplicatedStorage, and a few variables aswell including connection, unitPlaceHolder, sizeConnection and more. If they are defined, try running another well known animation by replacing your animation’s id with the other one.

These are the services:

local unitClick = {}
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local clickEvent = ReplicatedStorage.Remotes.clickOnUnit
local deleteUnit = ReplicatedStorage.Remotes.deleteUnit
local clientUnitSpawnEvent = ReplicatedStorage.Remotes.clientUnitSpawnEvent
local PhysicsService = game:GetService("PhysicsService")

local unitsFolder = ReplicatedStorage.Units
local unit1 = unitsFolder.Unit1Rig
local unit2 = unitsFolder.Unit2Rig

local unitSpawnEvent = ReplicatedStorage.Remotes.unitSpawnEvent
local currentUnitName = nil  
local unitPlaceHolder = nil
local sizeConnection
local rotationConnection
local hasClickedR = false
local connection
local inSelection = false
local rotationAngle = 0

unitClick.__index = unitClick

unitClick.unitclicks = {}

Is the animation owned by you? Or if it is listed under a group, is that group owned by you?
Is the animation made public? If you answer yes to all my questions, then try running another animation (replace the other ones id with yours and see if that causes an error too).

Yes, I do own the animation. Also this animation is on a module script, so does that make any difference if I’m playing it on a module script?