Is there any way to pause all animation at once? I was thinking you could iterate through the whole game and check if any animations exist so they would be paused, but I was wondering if there was a more efficient way to do this.
Iterating for animation objects / animators honestly is the best way, since itll be server sided it you could :Stop() just thru the server assuming youve done your animations serverside. For any client animation I would try to fire a remoteevent to client to stop the anim
Yeah that’s what I was thinking. Thanks though!
1 Like
One way that I’d consider more efficient is an implementation that uses an OOP architecture which handles all of the client-side and server-side animations in your experience.
--MODULE
local Animator = {}
function Animator.new(AnimatorObject)
return setmetatable({Animator = AnimatorObject, Tracks = {}}, {__index = Animator})
end
function Animator:Load(AnimationObject)
self.Tracks[AnimationObject.Name] = self.Animator:LoadAnimation(AnimationObject)
end
function Animator:Unload(AnimationName)
self.Tracks[AnimationName] = nil
end
function Animator:Play(TrackName)
if self.Tracks[TrackName] then self.Animations[TrackName]:Play() end
end
function Animator:Stop(TrackName)
if self.Tracks[TrackName] then self.Animations[TrackName]:Stop() end
end
function Animator:PlayAll()
for _, Track in ipairs(self.Tracks) do
if not Track.IsPlaying then Track:Play() end
end
end
function Animator:StopAll()
for _, Track in ipairs(self.Tracks) do
if Track.IsPlaying then Track:Stop() end
end
end
function Animator:Destroy()
self.Animator = nil
self.Tracks = nil
end
return Animator
--CLIENT
local Animator = require(PathToModule) --Require the module.
local NewAnimator = Animator.new(ReferenceToAnimatorObject) --Create an 'Animator' object wrapper.
NewAnimator:Load(ReferenceToAnimationObject) --Load an animation.
NewAnimator:Play(TrackName) --Play the loaded track.
NewAnimator:StopAll() --Stop all playing tracks.
3 Likes