the txt is the local script of my tool
and there the module script of my anime handler
local AnimationHandler = {}
AnimationHandler.__index = AnimationHandler
function AnimationHandler.new(humanoid)
local self = setmetatable({}, AnimationHandler)
self.humanoid = humanoid
self.animations = {}
self.tracks = {}
self.currentTracks = {}
self.animator = humanoid:WaitForChild("Animator")
return self
end
function AnimationHandler:AddAnimation(name, animationId, Priority)
local anim = Instance.new("Animation")
anim.AnimationId = animationId
self.animations[name] = anim
self.tracks[name] = self.animator:LoadAnimation(anim)
local track = self.tracks[name]
track:Play(0)
track.Priority = Priority
track:Stop()
end
function AnimationHandler:Play(name, slot)
slot = slot or "default"
-- Stop old track in the same slot
if self.currentTracks[slot] then
self.currentTracks[slot]:Stop()
end
local track = self.tracks[name]
if track then
track:Play()
self.currentTracks[slot] = track
end
return track
end
-- Stop a specific slot
function AnimationHandler:Stop(slot)
slot = slot or "default"
if self.currentTracks[slot] then
self.currentTracks[slot]:Stop()
self.currentTracks[slot] = nil
end
end
return AnimationHandler