-
What do you want to achieve? i wanna play the tower animations
-
What is the issue? i get the warning that anim track does not exists but it does
-
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:
PLEASE HELP MY WHOLE GAME IS BUGGED BECAUSE OF THIS