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: