Why does my script do this?

i have a script for a combat game, and im working on M1’s. Everythings going as planend except theres one small issue


the last M1 plays as if its the first M1 and im not so sure what the issue is. I narrowed the issue down to the numbers i put in the cooldowns but no matter what small - large whole number i put i still get this affect. what i want is after all the M1’s play the combo count wont restart until the cooldown is over. Ive made M1 systems before and ive never encountered this problem

heres my code:

Client (Its very long)
---------------------
--Services and Variables
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
----
local event = game.ReplicatedStorage.ActiveEvent
local anims = {
	M1 = hum.Animator:LoadAnimation(script:WaitForChild("Animations").M1),
	M2 = hum.Animator:LoadAnimation(script:WaitForChild("Animations").M2),
	M3 = hum.Animator:LoadAnimation(script:WaitForChild("Animations").M3),
	M4 = hum.Animator:LoadAnimation(script:WaitForChild("Animations").M4)
}
local count = 1
local stamina = player.Backpack.MovementValues.StaminaValue
----
local UIS = game:GetService("UserInputService")
local debounce = false
print("gr")
UIS.InputBegan:Connect(function(input, chat)
	if chat and stamina.Value <= 5 then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 and debounce == false then
		debounce = true
		if count == 1 then
			local check1 = event:InvokeServer({1, "Start"})
			if check1 == "Proceed" then
				print("Proceed")
				hum.WalkSpeed = 0
				hum.JumpHeight = 0
				anims.M1:Play()
				anims.M1:GetMarkerReachedSignal("Hit"):Connect(function()
					local check2 = event:InvokeServer({1, "M1"})
					if check2 == true then
						count = 2
						print(count)
						hum.WalkSpeed = 16
						hum.JumpHeight = 7.2
					end
				end)
			end
		elseif count == 2 then
			local check1 = event:InvokeServer({2, "Start"})
			if check1 == "Proceed" then
				print("Proceed")
				hum.WalkSpeed = 0
				hum.JumpHeight = 0
				anims.M2:Play()
				anims.M2:GetMarkerReachedSignal("Hit"):Connect(function()
					local check2 = event:InvokeServer({2, "M2"})
					if check2 == true then
						hum.WalkSpeed = 16
						hum.JumpHeight = 7.2
						count = 3
					end
				end)
			end
		elseif count == 3 then
			local check1 = event:InvokeServer({3, "Start"})
			if check1 == "Proceed" then
				print("Proceed")
				hum.WalkSpeed = 0
				hum.JumpHeight = 0
				anims.M3:Play()
				anims.M3:GetMarkerReachedSignal("Hit"):Connect(function()
					local check2 = event:InvokeServer({3, "M3"})
					if check2 == true then
						hum.WalkSpeed = 16
						hum.JumpHeight = 7.2
						count = 4
					end
				end)
			end
		elseif count == 4 then
			local check1 = event:InvokeServer({4, "Start"})
			if check1 == "Proceed" then
				print("Proceed")
				hum.WalkSpeed = 0
				hum.JumpHeight = 0
				anims.M4:Play()
				anims.M4:GetMarkerReachedSignal("Hit"):Connect(function()
					local check2 = event:InvokeServer({4, "M4"})
					if check2 == true then
						hum.WalkSpeed = 16
						hum.JumpHeight = 7.2
						count = 1
					end
				end)
			end
		end
		task.wait(.499)
		debounce = false
	end
end)
Server (Also a bit long)
local event = game.ReplicatedStorage.ActiveEvent
local TS = game:GetService("TweenService")
local SS = game:GetService("ServerStorage")

event.OnServerInvoke = function(plr, args)
	local char = plr.Character
	local HRP = char.HumanoidRootPart
	local BP = plr.Backpack
	local Attacking = BP.Status.CanAttack
	
	-----
	local hum = char.Humanoid
	local CDModule = require(SS.Modules:WaitForChild("Cooldown"))
	------------------
	--Print Check
	print("event reached")
	------------------

	if args[1] == 1 then
		if args[2] == "Start" then
			if CDModule.Cooldown(plr, true, "M1") == "Off CD" then
				if Attacking.Value == false then
					Attacking.Value = true
					CDModule.Cooldown(plr, false,"M1",.2)
					print("gr")
					return "Proceed"
				end
			end
		elseif args[2] == "M1" then
			print("M1")
			--stuff here
			Attacking.Value = false
			return true
		end
	elseif args[1] == 2 then
		if args[2] == "Start" then
			if CDModule.Cooldown(plr, true, "M2") == "Off CD" then
				if Attacking.Value == false then
					Attacking.Value = true
					CDModule.Cooldown(plr, false,"M2",.2)
					print("gr")
					return "Proceed"
				end
			end
		elseif args[2] == "M2" then
			print("M2")
			--stuff here
			Attacking.Value = false
			return true
		end
	elseif args[1] == 3 then
		if args[2] == "Start" then
			if CDModule.Cooldown(plr, true, "M3") == "Off CD" then
				if Attacking.Value == false then
					Attacking.Value = true
					CDModule.Cooldown(plr, false,"M3",.2)
					print("gr")
					return "Proceed"
				end
			end
		elseif args[2] == "M3" then
			print("M3")
			--stuff here
			Attacking.Value = false
			return true
		end
	elseif args[1] == 4 then
		if args[2] == "Start" then
			if CDModule.Cooldown(plr, true, "M4") == "Off CD" then
				if Attacking.Value == false then
					Attacking.Value = true
					CDModule.Cooldown(plr, false,"M4",3)
					print("gr")
					return "Proceed"
				end
			end
		elseif args[2] == "M4" then
			print("M4")
			--stuff here
			Attacking.Value = false
			return true
		end
	end
end

help would be greatly appriciated. Thank you for your time :slightly_smiling_face:

If I’m being honest I’m not entirely certain what you’re trying to accomplish nor which animation is the issue, since I don’t actually know what each animation is separately.

But I have an idea, and it may solve it.

if you want this to be a continuous “combo” sequence, you may want to reset count to 1 upon a check being false or if the player fails to click within an allotted time frame.

1 Like