Hi, I am using an animations module, and when I run the Stop() function, sometimes it won’t stop the animation as intended
Module:
local Cache = {}
local Animations = {}
local LoadedAnimation
local LoadedAnimation2
local LoadedAnimation3
local ContentProvider = game:GetService("ContentProvider")
function GetAnimator(Player)
local Character = Player.Character
if not Character then return end
local Humanoid = Character:FindFirstChild("Humanoid")
if not Humanoid then return end
local Animator = Humanoid:FindFirstChild("Animator")
return Animator
end
function LoadAnimation(Player, Animation)
Cache[Player] = Cache[Player] or {}
local Anim = Cache[Player][Animation]
if not Anim then
local Animator = GetAnimator(Player)
if not Animator then return end
ContentProvider:PreloadAsync({Animation})
Anim = Animator:LoadAnimation(Animation)
Cache[Player][Animation] = Anim
end
return Anim
end
function LocalStopAnimation(Player)
if not Cache[Player] then return end
for _, Anim in pairs(Cache[Player]) do
Anim:Stop()
end
end
function Animations:PlayAnimation(Player, Animation)
local Anim = LoadAnimation(Player, Animation)
if not LoadedAnimation then
LoadedAnimation = Anim
elseif LoadedAnimation and not LoadedAnimation2 then
LoadedAnimation2 = Anim
elseif LoadedAnimation and LoadedAnimation2 and not LoadedAnimation3 then
LoadedAnimation3 = Anim
end
if not Anim then
return warn("Error retrieving/loading Animation")
end
Anim:Play()
end
function Animations:StopAnimation(Player)
if not Cache[Player] then return end
if LoadedAnimation then
LoadedAnimation:Stop()
LoadedAnimation = nil
end
if LoadedAnimation2 then
LoadedAnimation2:Stop()
LoadedAnimation2 = nil
end
if LoadedAnimation3 then
LoadedAnimation3:Stop()
LoadedAnimation3 = nil
end
end
return Animations
Any help would be appreciated, thanks!