Hello. I am attempting to write code that processes animations whereby a Server script sends an event to the player. This event is processed by a LocalScript that plays the animation.
I am playing animations in series and I pass this information as a table. The final animation of this table is always a looped animation. In order to prevent animations from getting jumbled up, I introduced a debounce. When the debounce is true, new series of animations cannot be played. The debounce is set to false when the final, looped animation is reached.
Here is my code:
local debounce = script.Parent.IsAnimating
local function playAnimationSequence(animationData)
if debounce.Value then
return
end
debounce.Value = true
stopAllAnimations()
--
for i, animInfo in ipairs(animationData) do
local animTrack = playAnimation(animInfo.Name, animInfo.Speed or 1)
if animTrack then
if animInfo.Looped then
debounce.Value = false
-- Loop the animation indefinitely
return
else
-- Non-looped animations need to wait until they finish
task.wait(animTrack.Length / math.abs(animInfo.Speed or 1)) -- Wait for the duration of the animation
end
end
end
end
This is how I am handling animations on the server side:
elseif input == Enum.UserInputType.MouseButton1 and isbegan and equippingtool and player:GetAttribute("isLoaded") and not isAiming and not isTrailing and not isOrdering and not Skirmish and not debounce.Value then
wait(0.25)
MakeReady = not MakeReady
if MakeReady then
MusketAnimationEvent:FireClient(player, {
{Name = "MakeReady", Speed = 1.5},
{Name = "MakeReadyIdle", Speed = 1, Looped = true},
})
else
MusketAnimationEvent:FireClient(player, {
{Name = "MakeReady", Speed = -1.5},
{Name = "Default", Looped = true},
})
end
The main issue I’m running into is whenever I spam click, it seems to skip over animations. So the animations do not begin at the logical, last position. I have included a video outlining this: