Hi everyone, this is my first time posting here so please bear with me.
I am currently creating a melee combat system and I’ve run into a problem that I don’t really know how to fix. I have 5 animations that are very short in duration and therefore should play pretty quickly in game, but I find that their speed is actually inconsistent: while they play correctly most of the time, some times they are severely slowed down;
This is how the animation looks, the last set of KeyFrames makes it so that after the punch/kick animation has “finished”, the player returns to his idle pose. My goal was to make it so that if a player clicked their mouse slowly, the animations would have time to finish and therefore making their character return to the idle pose, but if a player clicked quickly the animation would get interrupted by the next one before the character has the chance to return to the idle pose. Here’s two gifs to let you understand better:
Slow clicking:
Spam clicking:
I noticed that the problem tends to happen when the player clicks slowly, playing a new animation when the previously played one is returning to the idle pose, rather than when the player spam clicks.
Here’s a video that clearly shows the problem, as you can see some of the animations are slowed down (I’m sorry for the bad quality and low fps)
This is my local script
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
local animator = hum:WaitForChild("Animator")
local data = {}
local combo = 1
local debounce = false
local mainCooldown = game.ReplicatedStorage:WaitForChild("mainCooldown")
local a1 = Instance.new("Animation")
local a2 = Instance.new("Animation")
local a3 = Instance.new("Animation")
local a4 = Instance.new("Animation")
local a5 = Instance.new("Animation")
a1.AnimationId = "rbxassetid://14027589675"
a2.AnimationId = "rbxassetid://14027924810"
a3.AnimationId = "rbxassetid://14028761278"
a4.AnimationId = "rbxassetid://14027924810"
a5.AnimationId ="rbxassetid://14027797082"
local lastUsed = tick()
local anims = {
animator:LoadAnimation(a1),
animator:LoadAnimation(a2),
animator:LoadAnimation(a3),
animator:LoadAnimation(a4),
animator:LoadAnimation(a5)
}
for i,v in anims do
anims[i].Name = "Combo"..i
end
uis.InputBegan:Connect(function(input, chatting)
if chatting then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if debounce or mainCooldown.Value == true then return end
debounce = true
mainCooldown.Value = true
if tick() - lastUsed > 1.6 then
combo = 1
end
lastUsed = tick()
for i,v in pairs(animator:GetPlayingAnimationTracks()) do
if string.find(v.Name, "Combo") then v:Stop() end --The previous attack animation might still be playing ()
end
wait()
anims[combo]:Play()
if combo == 5 then
combo = 1
wait(.3)
mainCooldown.Value = false
wait(.4)
debounce = false
else
combo +=1
wait(.2)
mainCooldown.Value = false
debounce = false
end
end
end)
All of them have a priority of Action4.
I hope someone can help me because I wasn’t able to find anything that could help me