Hi, I have made this AnimationModule which handles animations easily, rather than me callling an animation on each client script, but it doesn’t seem to work.
Module Script:
local Animations = {}
local Services = {
RunService = game:GetService("RunService")
}
local CurrentAnimation
local Heartbeat = Services.RunService.Heartbeat
function Animations:Play(Player, Animation, Duration)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Animation = Animator:LoadAnimation(Animation)
if Duration ~= nil and CurrentAnimation == nil then
Animation:Play(Duration)
CurrentAnimation = Animation
elseif Duration == nil and CurrentAnimation == nil then
Animation:Play()
CurrentAnimation = Animation
elseif Duration ~= nil and CurrentAnimation then
repeat Heartbeat:Wait() until CurrentAnimation == nil
Animation:Play(Duration)
CurrentAnimation = Animation
elseif Duration == nil and CurrentAnimation then
repeat Heartbeat:Wait() until CurrentAnimation == nil
Animation:Play()
CurrentAnimation = Animation
end
end
function Animations:Stop(Player, Animation, Duration)
if Duration ~= nil and CurrentAnimation ~= nil then
CurrentAnimation:Stop(Duration)
CurrentAnimation = nil
elseif Duration == nil and CurrentAnimation ~= nil then
CurrentAnimation:Stop()
CurrentAnimation = nil
end
end
return Animations
Client script:
if Back then
AnimationModule:Play(plr, Back, 0.5)
end
Any help would be appreciated, thanks.