Hi,
I’m making a game tower defense and I want to load animations into the mobs and the towers. The thing is that the load animation thing is deprecated and idk how to fix it. I already visited the roblox animation docs but i really can’t figure it out. Anyone help me please.
This is what I have so far:
(LocalScript inside of StarterPlayerScripts)
local function setAnimation(object, animName)
local humanoid = object:WaitForChild("Humanoid")
local animationsFolder = object:WaitForChild("Animations")
if humanoid and animationsFolder then
local animationObject = animationsFolder:WaitForChild(animName)
if animationObject then
local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
local animationTrack = animator:LoadAnimation(animationObject)
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 exist")
return
end
end
workspace.Mobs.ChildAdded:Connect(function(object)
playAnimation(object, "Walk")
end)
workspace.Game.Towers.ChildAdded:Connect(function(object)
playAnimation(object, "Idle")
end)
Example of Tower inside of ReplicatedStorage > Towers