Sword combo script help

Im currently trying to make a sword for my fighting game and wanted to have a sorta combo animation for when you click. but ive run into a issue where it either plays only the first part or it plays all 3 parts one by one aftter only clicking once.

  1. What do you want to achieve? Keep it simple and clear!
    i wanna have a sorta 3 part combo animation, with 1 part of the animation playing after 1 click

  2. What is the issue? Include screenshots / videos if possible!
    either it only plays part 1 of the combo animations or it plays all 3 of them in a row after 1 click only

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    -ive tried using return but it just seems to stop after the first part of the animation
    -ive tried using end but it just plays all 3 animation parts after only 1 click

im still pretty new to scripting and most of the code is either a modified version of a script or just multiple different scripts packed together

--this script is the one that plays all 3 animations after 1 click

script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		local combo = 1
		
		if combo == 1 then
		local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation1)
		animation:Play()
		script.Disabled = true
		wait(0.5)
		script.Disabled = false
		combo += 1
		end


			if combo == 2 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation2)
				animation:Play()
				script.Disabled = true
				wait(0.5)
				script.Disabled = false
				combo += 1
				end

				
				if combo == 3 then
					local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation3)
					animation:Play()
					script.Disabled = true
					wait(0.5)
					script.Disabled = false
					combo = 1
					end

i suck at coding. even after looking at multiple dev forms and tutorials i still suck

1 Like

You dont Need To Stop The Script. I can Help You Here Is The Code Try To Understand it


-- This is a local script dont put it in server script bc local scripts work for only 1 player

script.Parent.Activated:Connect(function()
       if Combo == 1 then
               -- do Stuff here like play the animation DONT disable the script

                 Combo = 2

       elseif Combo == 2 then
                  Combo = 3
     elseif Combo == 3 then
               Combo = 1 -- Here!
        end
end)
1 Like

You’ll understand it later.
What is currently happening in your code is that when player clicks, first condition is ran, then the second, and then the third in only execution.
What you wanna do is store your Combo variable outside the click, and every click make it bigger, and as @Weaved23 wrote, structure your conditions with else ifs.

When you write code, imagine what should be happening line by line.

When I made my code for a sword fighting game, I named all my animations “Swing1, Swing2”, and set the combo = 0, when you press mouse1, the combo += 1, and the way I played an animation was Humanoid.Animator:LoadAnimation(“Swing”…combo):Play(), here’s an example:

combo = 0
UIS.InputBegan:Connect(function(input, isTyping)
    if input.UserInputType = Enum.UserInputType.MouseButton1 then
       combo += 1
       humanoid:LoadAnimation("Slash"..combo)
       if combo > 5 then
          combo = 1
       end
end)

ok i read the script and i somewhat understand, but when i went to do the scripting stuff, it shows theres a error. what did i get wrong?

script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		local Combo = 1

		script.Parent.Activated:Connect(function()
			if Combo == 1 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation1)
				animation:Play()
				Combo = 2

			elseif Combo == 2 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation2)
				animation:Play()
				wait(1)
				Combo = 3

			elseif Combo == 3 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation3)
				animation:Play()
				wait(1)
				Combo = 1

if Combo < 3 then
local Combo = 1


end
end)

Why are you Doing script.Parent.Activated AND Mouse.button1down at the same time thats why it isnt working

And script.Parent.Activated Doesnt Even Have parameter called Mouse And you Dont Even Need To Check If The Tool Is Equipped. Activated Fires WHENEVER The Tool Was Pressed Like If I press My Mouse Button1 It Will Fire IF I have The Tool Equipped.

so do i remove the script.Parent.Equipped:Connect(function(Mouse)?

ok i looked back on this code and found out what i did wrong, and it works! but it only plays the 1st part of the animation, so what do i do?

script.Parent.Activated:Connect(function()
		local Combo = 1

			if Combo = 1 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation1)
				animation:Play()
				Combo = 2

			elseif Combo = 2 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation2)
				animation:Play()
				Combo = 3

			elseif Combo = 3 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation3)
				animation:Play()
				Combo = 1

if Combo < 3 then
Combo = 1

end
end
end)

Remove The if Combo < 3 then
Combo = 1

end

ok so i did that and it still only plays the first part of the animation

heres the code again

script.Parent.Activated:Connect(function()
		local Combo = 1

			if Combo == 1 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation1)
				animation:Play()
				Combo = 2

			elseif Combo == 2 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation2)
				animation:Play()
				Combo = 3

			elseif Combo == 3 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation3)
				animation:Play()
				Combo = 1


end
end)

heres animation part 2 and 3 for reference

script.Parent.Activated:Connect(function()
		local Combo = 1

			if Combo == 1 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation1)
				animation:Play()
				Combo = 2

			elseif Combo == 2 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation2)
				animation:Play()
				Combo = 3

			elseif Combo == 3 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation3)
				animation:Play()
				Combo = 1


end
end)

You have your Combo = 1 each time you activate it, you need to place the combo outside, like this:

local Combo = 1
script.Parent.Activated:Connect(function()
			if Combo == 1 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation1)
				animation:Play()
				Combo = 2

			elseif Combo == 2 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation2)
				animation:Play()
				Combo = 3

			elseif Combo == 3 then
				local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation3)
				animation:Play()
				Combo = 1


end
end)

Now, you have your combo set to 1, instead of setting it to 1 each time you activate the tool.

1 Like

ayeee it works now! tysm man! :smiley:

No problem, happy to help, enjoy scripting.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.