Playing animations in an order (combos)

  1. I want to achieve a combo system for my combat system and understand how I could make a combo.

  2. I have my combat system ready and the punches randomized but I want to make a combo instead of randomizing the punches.

please let me know in which ways I could make my animations play one after another.

my current randomizing script.

tool.Activated:Connect(function()
	local punches = {
		rightPunch,
		leftPunch,
		leftKick,
		rightKick,
		straightKick,
		doublePunch
	}
	
	local anim = player.Character.Humanoid:LoadAnimation(punches[math.random(#punches)])
	anim:Play()
	
end)
1 Like

You can use ipairs

for i, v in ipairs(punches) do
	local anim = player.Character.Humanoid:LoadAnimation(punches[i])
	anim:Play()
    anim.Stopped:Wait() 
end

-- or

for i = 1,#punches do
	local anim = player.Character.Humanoid:LoadAnimation(punches[i])
	anim:Play()
    anim.Stopped:Wait()
end

New code:

local AnimPlayed = 0
local Debounce = false
local punches = {...}

tool.Activated:Connect(function() 
if not Debounce then
Debounce = true
if AnimPlayed < #punches then
    AnimPlayed += 1
    local anim = player.Character.Humanoid:LoadAnimation(punches[AnimPlayed])
	anim:Play()
    anim.Stopped:Wait() 
    Debounce = false
elseif AnimPlayed >= #punches then
    AnimPlayed = 1
    local anim = player.Character.Humanoid:LoadAnimation(punches[AnimPlayed])
	anim:Play()
    anim.Stopped:Wait() 
    Debounce = false
    end
end
end)

@Dev_Simphony try this ^

1 Like

this is not working since I dont want it to happen in 1 click. After each individual click I want the animation to change in order.

Oh, okay I probably know what you want.

1 Like

So can you help me out with that? or is it too hard

its not working well. Let me show you a video of how its doing.

https://gyazo.com/8c327327850032b9cf3bed28e4f4d07c

So the problem is that the animations are overlapping?

1 Like

Yes I am pretty sure this might be the problem. And some animations that are not suppose to be playing play.

Let me know if adding the new code fixed it.

1 Like

Sadly did not fix it. Thanks for trying to help out tho

Just realized you want each animation in order , ignore this.

1 Like

I did something like this a while ago. What I did was I made it so every time you activate the tool a number value goes up by 1 and ends at the number of animations you have and then goes back down to 1. When activating the tool it checks an if statement. For example if number == 1 then it plays the first animation and if number == 2 it plays the second animation and so on. I don’t know if this will work but you can try something like that. Good luck! I hope you fix your problem and I hope this helps in some way. Sorry if this doesn’t work.

1 Like

This is exactly what I did :thinking:.

That is extremely similar to what I did but I think how I had it done was in a less complicated way. But I’m not sure why both ways wouldn’t work just the same.
Did your script work for you?

Maybe you could do something like this?

tool.Activated:Connect(function()
local punches = {
rightPunch,
leftPunch,
leftKick,
rightKick,
straightKick,
doublePunch
}

local anim1 = punches[1]
local anim2 = punches[2]
local anim3 = punches[3]
local anim4 = punches[4]
local anim5 = punches[5]
local anim6 = punches[6]

|local load1 = Humanoid:LoadAnimation(punches[1])
|local load2 = Humanoid:LoadAnimation(punches[2])
|local load3 = Humanoid:LoadAnimation(punches[3])
|local load4 = Humanoid:LoadAnimation(punches[4])
|local load5 = Humanoid:LoadAnimation(punches[5])
|local load6 = Humanoid:LoadAnimation(punches[6])

load1:Play()
wait(-- whatever duration the animation is --)
load1:Stop()
load2:Play()
wait(-- whatever duration the animation is --)
Load2:Stop()
Load3:Play()
wait(-- whatever duration the animation is --)
Load3:Stop()
Load4:Play()
wait(-- whatever duration the animation is --)
Load4:Stop()
Load5:Play()
wait(-- whatever duration the animation is --)
Load5:Stop()
Load6:Play()
wait(-- whatever duration the animation is --)
Load6:Stop()
end)

Keep in mind that I’m new to coding so something here could be wrong.

Your code won’t work because the animation must be played in order after activating the tool.

Awesome it worked. Thanks mate!! The animations no go in order as expected :slight_smile: