I have a turn-based game that has animations based on different game states. However, this can prove troublesome for when a lengthy battle occurs, and when 256 of the same animations are loaded over time.
I have these two functions:
function LoadAnimation(AnimationObject, Target)
if (BattleInfo.MemberAnimations[Target]) then --if the humanoid was already used as a target
if (BattleInfo.MemberAnimations[Target][AnimationObject]) then --check if the humanoid already loaded the animation object
return BattleInfo.MemberAnimations[Target][AnimationObject] --return the animation track if so
else --otherwise
BattleInfo.MemberAnimations[Target][AnimationObject] = Target:LoadAnimation(AnimationObject) --make animationobject point to the animationtrack
return BattleInfo.MemberAnimations[Target][AnimationObject] --return the animation track
end
else --if the humanoid is fresh
BattleInfo.MemberAnimations[Target] = {}; --set the humanoid to point to an animation storage table
BattleInfo.MemberAnimations[Target][AnimationObject] = Target:LoadAnimation(AnimationObject) --save animation to table
return BattleInfo.MemberAnimations[Target][AnimationObject] --return animation
end
end
function StopAnimation(Name, Target)
-- MemberAnimations -> [Table (Humanoid Object/Target)] -> AnimationObject Name == AnimationTrack
--MemberAnimations -> Table -> Animation Object -> Animation Track
for i, v in pairs(BattleInfo.MemberAnimations[Target] or {'None'}) do
print(i, v, Name, Target)
print(v.Animation, Name, v.Animation == Name)
if Name or (v.Animation and v.Animation == Name) then
v:Stop()
return true, warn('Found animation', Name and Name.Name or 'undefined', 'and stopped it.')
end
end
return warn('Couldn\'t find animation', Name)
end
The issue with StopAnimation is that it doesn't remove all links to AnimationTracks within the table. I use userdata-based indices for my table, but that shouldn't be an issue because the humanoid never dies, so I doubt it has a chance to modify itself in such a way that it couldn't be recognized as the same table index as the one at the start of the battle.
The issue with LoadAnimation is that some animations refuse to play after one other animation is played.
For example, I have two animation objects: one that plays when their weak point gets hit, and the one that plays after (and loops) to indicate that they're down and cannot act. When they get back up (which is shown by another animation), the two animation objects refuse to play on the characters/enemies again.
Is there any way to fix these issues? Is there any way to improve my code? Please let me know.

4 comments
TROLE TROEL ALERT TROLE RTROLE TROEL ALERT TROLE LULULL TROLE WUT A TROEL
GNOME TROEL
EPIC TROEL WHY U MAD BRO EPIC TROEL UR MAD BRO LUL U MAD BRO LULULUL TROELED ALEPHKING ALEPH HAHAH
LMFOALMFOALMFOAMLMOFA GOOd 1 DUDE