Second Punch Animation won't play

So, I’m trying to make a basic combat system for now, but a basic code won’t work. I can’t seem to figure out why…

I’ve tried the devforum searching for a solution but that didn’t help. Tried rewriting the code to having the keycode be Q and E. That worked but it’s not the goal. The goal is to have the animations play when you only click mousebutton1. It prints out the correct combo. Prints 1 for it to play the right combo. It also prints 2 for it to play the left combo, but it doesn’t play…

If you’re wondering what the AnimationID variable is it’s a nil value.

UserInputService.InputBegan:Connect(function(input, key)

    if key or debounce then return end

     if input.UserInputType == Enum.UserInputType.MouseButton1 then

    print(combo)

    debounce = true

    if combo then

    combo = 2

    AnimationID = Humanoid:LoadAnimation(right)

    AnimationID:Play()

elseif combo == 2 then

    debounce = true

    AnimationID = Humanoid:LoadAnimation(left) -- doesn't play the second punch animation why?

    AnimationID:Play()

    end

    wait(0.5)

    debounce = false

    isDamaged = false -- u can ignore this

    if combo == 2 then

        wait(1)

        combo = 1

    end

    end

end)

Don’t know why the code is spaced out like that but ok lol

Your code checks if combo exists not if combo is equal to one.

I had originally changed that actually

if combo == 1 then

But it still gave me the same result so that’s why as of now you see if combo then.
I tried writing it differently but :confused:

Could you try this? My guess is that the issue is either to do with the first animation never stopping and preventing the new one to play? Also why do you have a wait in if combo == 2?

Also you have to change the top so it loads the correct animation

local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

local debounce = false
local combo = 1

local LastAnimation = nil
local Animations = {}
Animations["Right"] = Humanoid:LoadAnimation(right)
Animations["Left"] = Humanoid:LoadAnimation(left)

UserInputService.InputBegan:Connect(function(input, processed)
	if debounce or processed then
		return
	end
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		debounce = true
		if LastAnimation then
			LastAnimation:Stop()
			LastAnimation = nil
		end
		if combo == 1 then
			LastAnimation = Animations["Right"]
			LastAnimation:Play()
			combo = 2
		elseif combo == 2 then
			LastAnimation = Animations["Left"]
			LastAnimation:Play()
			combo = 1
		else
			print("combo is not valid")
		end
		wait(0.5)
		debounce = false
	end
end)

I have the wait because it’s how I prevent the same number from being printed twice.

Your code worked thank you.

I think the problem was the animation not stopping so thank you.

1 Like