M1 combo animation bug

A continuation of another thread, as I felt like making a new post was a better decision.

I’ve come to figure out how to make it work. Just a little bug happening.

-- left some parts out for better readability 

local debounce = false
local timeThreshold = 0.75
local previousInput = 0

tool.Activated:connect(function()
	if tool.Enabled and not debounce then
		debounce = true

		loadAnimation("Straight"):Play()
		loadAnimation("Straight").Stopped:Wait()
		
		if tick() - previousInput <= timeThreshold then
			loadAnimation("Hook"):Play()
			loadAnimation("Hook").Stopped:Wait()
			
			if tick() - previousInput <= timeThreshold then
				loadAnimation("Shove"):Play()
				loadAnimation("Shove").Stopped:Wait()
			end
		end
		
		wait(0.25)
		debounce = false		
	end

	previousInput = tick()
end)

After doing a full combo and then clicking another time, both the straight and hook animations play, instead of just the straight animation.

97a531e5d03f3d48ed322e01dcdf760e

Might be a very obvious fix, am just very tired at the moment. Please let me know if you have any solutions to this. I’ll be happy to provide any more information.

You’re updating previousInput too late - it should probably be happening immediately after you engage the debounce.

Unless I’m misunderstanding the kind of input scheme you’re trying to build. From what I can tell, you want further animations as the player keeps clicking?

Aside: tick is not the timing mechanism to use for gameplay stuff like this. You should use Workspace.DistributedGameTime.

1 Like

You should use Workspace.DistributedGameTime.

Ah, I didn’t know that existed. Is there a difference between workspace.DistributedGameTime and time()?

Unless I’m misunderstanding the kind of input scheme you’re trying to build. From what I can tell, you want further animations as the player keeps clicking?

Yes. If the player clicks once they will perform one attack, twice then they will perform two attacks in a row, and so on. In other words, an M1 combo.

You’re updating previousInput too late - it should probably be happening immediately after you engage the debounce.

c7bf9966bd5123b2267b74ac5e89fddf

Updated Script
local debounce = false
local timeThreshold = 0.75
local previousInput = 0

tool.Activated:connect(function()
	print("click")
	
	if tool.Enabled and not debounce then
		debounce = true
		previousInput = time()

		loadAnimation("Straight"):Play()
		loadAnimation("Straight").Stopped:Wait()
		print("combo 1")
		
		if time() - previousInput <= timeThreshold then
			loadAnimation("Hook"):Play()
			loadAnimation("Hook").Stopped:Wait()
			print("combo 2")
			
			if time() - previousInput <= timeThreshold then
				loadAnimation("Shove"):Play()
				loadAnimation("Shove").Stopped:Wait()
				print("combo 3")
			end
		end
		
		wait(0.25)
		debounce = false		
	end
end)

When I tried that, it made it so clicking once skips ‘combo 1’ and plays ‘combo 2’. Attempting to prompt ‘combo 3’ always fails.

Doesn’t seem to be, so it looks like a good drop-in replacement :+1:

It looks like you need to be inspecting some value that indicates if they’ve clicked during an animation, a value which you reset before it is used. Consider the following which uses continueCombo for just that:

local tool = script.Parent
local combo = nil
local continueCombo = false
local anim1 = loadAnimation("Straight")
local anim2 = loadAnimation("Hook")
local anim3 = loadAnimation("Shove")

local function startCombo()
    combo = 1
    continueCombo = false
    anim1:Play()
    anim1.Stopped:Wait()

    if continueCombo then
        combo = 2
        continueCombo = false
        anim2:Play()
        anim2.Stopped:Wait()
        if continueCombo then
            combo = 3
            anim3:Play()
            anim3.Stopped:Wait()
        end
    end
    wait(0.25)
    combo = nil
end

tool.Activated:Connect(function ()
    if not combo then
        startCombo()
    else
        continueCombo = true
    end
end)
3 Likes

Thank you! I’ve tried something like this before but it didn’t work, which is why I tried using tick() instead. I haven’t really dealt with stuff like this before.

Is there still a way to implement a time threshold? As in the time frame the player has to click in before the combo resets. While testing I noticed that the player has to click at the exact moment the current animation ends for the combo to continue, though I’d like there to be a little more space.

wait(0.25)
combo = nil

I believe this is pretty much the same but it also acts as the tool cooldown, which I’d like to keep separate, if that makes sense.

2 Likes