First attacks in cycle do not respect debounce

So, I’m working on a battlegrounds type game, and I’ve been struggling with a bug for the better part of week now. Everything else is going smoothly, except this one annoying issue that is borderline game breaking. I’m hoping someone could help me with this.

I have a character with a combo system that cycles through 4 animations. These work fine, except for the first time the cycle is triggered. So, the first 4 attacks do not respect the debounce I have set up. After those 4, everything works as intended, and the attacks come out when they’re supposed to.

I tried looking around on this forum, but it seems my issue is kinda specific. As I mentioned earlier, AI was not of any use to me here (and I use it as a last resort).

Anyway, here comes the server script for handling the attacks. I will also attach a short video demonstrating the bug.

local players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")

local ClickAttackDebounces = {}

-- JOHN TESTING MOVES
local JohnEvents = Events:WaitForChild("John")
local JohnInactivity = {}
local slamDebounce = -math.huge
local isMidCombo = false
local slamActive = false

-- M1 combo, uses table debounce logic
JohnEvents.M1Combo.OnServerEvent:Connect(function(player)
	local character = player.Character
	if character == nil then
		return
	end
	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid == nil then
		return
	end
	if humanoid.Health <= 0 then
		return
	end
	if ClickAttackDebounces[player] then
		return
	end
	-- For John specifially, if he's in currently waiting for inactivity to be over (which HE SHOULD NOT BE)
	if JohnInactivity[player] then
		task.cancel(JohnInactivity[player])
	end

	local JohnCombo = player.Values.JohnCombo

	JohnInactivity[player] = task.delay(1.5, function() -- if john doesn't attack for 1.5 seconds, reset combo
		print("Reset for inactivity.")
		JohnCombo.Value = 1
	end)

	ClickAttackDebounces[player] = true
	local Animation = script.JohnAttacks[tostring(JohnCombo.Value)]
	local LoadedAnim = humanoid.Animator:LoadAnimation(Animation)
	LoadedAnim:Play()
	isMidCombo = true

	if JohnCombo.Value >= #script.JohnAttacks:GetChildren() or slamActive == true then -- if for some reason the value is more than than 1 set it to 1 
		JohnCombo.Value = 1
	else
		JohnCombo.Value += 1
	end

	task.wait(LoadedAnim.Length + 0.1)

	if ClickAttackDebounces[player] then
		ClickAttackDebounces[player] = nil
		isMidCombo = false
	end
end)

-- Launching down slam, uses timer debounce logic
JohnEvents.DownwardSlam.OnServerEvent:Connect(function(player)
	local character = player.Character
	local timestamp = os.clock()
	if character == nil then
		return
	end
	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid == nil then
		return
	end
	if humanoid.Health <= 0 then
		return
	end

	if timestamp > slamDebounce and not isMidCombo then -- checks for debounce and if john isnt in the middle of an m1 attack
		slamDebounce = timestamp + 1

		local Animation = ReplicatedStorage.Attacks.JohnSpecials.DownSlam
		local LoadedAnim = humanoid.Animator:LoadAnimation(Animation)
		slamActive = true -- honestly, i dont know how but this helps things not break. and if it ain't broke, don't fix it!
		LoadedAnim:Play()
		ClickAttackDebounces[player] = true -- makes sure that you can't activate an m1 attack mid swing
		task.wait(0.88)
		ClickAttackDebounces[player] = nil
		slamActive = false
	end
end)

If any other information is needed, I will provide it asap.
Video of the bug
(i am spamming mouse 1 for the entire duration)

1 Like

Which debounce isn’t working specifically? Have you done any print debugging?! What about the client code?

1 Like

It’s a pretty easy fix. Just preload your animations (animations take some extra time to load when you :LoadAnimation them for the first time). That will fix your issue.

2 Likes

The table debounce is the one not working. And yes, print debugging was one of the first things i tried. Client code only activates a server event, so the issue would not be there.

Alright, I will try this when I get home. Thanks in advance!