M1 debounces not working halp

Err soo… my script randomly broke after changing it up a bit and I can’t really figure out why it’s broken. It’s really odd because it works if you spam it quick enough even thought it should because of the debounce, but if you do it normally it doesn’t get past the first m1…

I tried to make it like, the m1 timer is made, and the debris deletes it after 2 seconds, but if the m1 tool is activated again before that it moves onto the next m1 and creates another timer, until the last one.

Client :3

-- Variables

local event = script.Parent:WaitForChild("RemoteEvent")
local tool = script.Parent
local equipped = false
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local hum = plr.Character:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local idleAnim = animator:LoadAnimation(script:WaitForChild("Idle"))
local debounce = false

-- idle

tool.Equipped:Connect(function()
	equipped = true
	local idleAnim = animator:LoadAnimation(script:WaitForChild("Idle"))
	idleAnim:Play()
	tool.Unequipped:Wait()
	print("ok we done")
	equipped = false
	idleAnim:Stop()
end)

tool.Activated:Connect(function()
	if debounce == false then
		debounce = true
		if plr.Character:FindFirstChild("Stunned") ~= nil then
			print("stunned")
		return
	end
		if plr.Character:FindFirstChild("Busy") ~= nil then
			print("busy")
		return
	end
	if hum:GetState() == Enum.HumanoidStateType.Freefall then
		event:FireServer("Aerial")
	elseif hum.MoveDirection ~= Vector3.new(0,0,0) then
		event:FireServer("Moving")
	else
		event:FireServer("Neutral")
	end	
	task.wait(0.05)
		debounce = false
	end
end)

Server (the one that’s being weird is moving, so I’ll show the moving function)

event.OnServerEvent:Connect(function(plr,attack)
	if attack == "Moving" then
		moving(plr)
	elseif attack == "Neutral" then
		neutral(plr)
	elseif attack == "Aerial" then
		aerial(plr)
	end
end)
function moving(plr)
	if debounce1 == false then
		debounce1 = true
		
		-- Stun
		task.spawn(function()
			for _ = 1,25 do
				if plr.Character:FindFirstChild("Stunned") ~= nil then
					return
				end
				task.wait(0.01)
			end
		end)
		
		--Variables
		local char = plr.Character
		local hum = char.Humanoid
		local animator = hum:WaitForChild("Animator")
		local hrp = char.HumanoidRootPart
		
		--Functions
		
		
		local function checkHitbox(hitbox)
			local filterObjects = {char}
			local hitboxPos = hitbox.CFrame
			local hitboxSize = hitbox.Size
			local maxObjectsAllowed = 10
			local params = OverlapParams.new(filterObjects,Enum.RaycastFilterType.Exclude,maxObjectsAllowed,"Default")
			local objectsInSpace = workspace:GetPartBoundsInBox(hitboxPos,hitboxSize,params)
			
			return objectsInSpace
		end
		
		--
		
		task.spawn(function()
			hum.WalkSpeed = 14
			task.wait(0.5)
			hum.WalkSpeed = char.WalkSpeedValue.Value
		end)
		
		
		if char:FindFirstChild("M1Combo") == nil then
			m1 = 1
			coroutine.resume(coroutine.create(function()
				task.wait(0.3)
				debounce1 = false
			end))
			print(m1)
			print("creating")
			local combo = Instance.new("StringValue",char)
			combo.Name = "M1Combo"
			debris:AddItem(combo,2)
			local anim = animator:LoadAnimation(script:FindFirstChild(m1))
			anim:Play()
		task.wait(0.15)
			local hitbox = dmg.HitboxCreate(hrp.CFrame + hrp.CFrame.LookVector * 2,Vector3.new(3,5,3),0.1)
			hitbox.Anchored = false
			local weld = Instance.new("WeldConstraint",hitbox)
			weld.Part0 = hitbox
			weld.Part1 = hrp
			-- check for hitboxes

		--[[	db = {}
			task.spawn(function()
				task.wait(0.1)
				while hitbox.Parent ~= nil do]]
					for _,v in pairs(checkHitbox(hitbox)) do
						if v.Parent:FindFirstChild("Humanoid") then
							if v.Parent ~= char then
								if v.Name == "Hitbox" then
									--if not table.find(db,v.Parent) then
									---	table.insert(db,v.Parent)
										dmg.Dmg(v.Parent,3,plr.Name,ss.HitAnim)
										local forward = hrp.CFrame.LookVector * 30
										dmg.Knockback(forward,v.Parent,0.25,plr)
										dmg.Stun(v.Parent,0.3)
										local meleeHit = effects.MeleeHit:Clone()
										meleeHit.Parent = hrp
										meleeHit:Emit(30)
										debris:AddItem(meleeHit,1)
									end
								end
							end
						end
					--[[end
				end
			end)]]
		elseif m1 == 1 then
			m1 = 2
			coroutine.resume(coroutine.create(function()
				task.wait(0.3)
				debounce1 = false
			end))
			debounce1 = false
			print("middle")
			local combo = Instance.new("StringValue",char)
			combo.Name = "M1Combo"
			debris:AddItem(combo,2)
			local anim = animator:LoadAnimation(script:FindFirstChild(m1))
			anim:Play()
			task.wait(0.1)
			dmg.Busy(char,0.25)
			local hitbox = dmg.HitboxCreate(hrp.CFrame + hrp.CFrame.LookVector * 2,Vector3.new(3,3,4),0.1)
			hitbox.Anchored = false
			local weld = Instance.new("WeldConstraint",hitbox)
			weld.Part0 = hitbox
			weld.Part1 = hrp
			
			-- check for hitboxes
			
			task.wait(0.1)
					for _,v in pairs(checkHitbox(hitbox)) do
						if v.Parent:FindFirstChild("Humanoid") then
							if v.Parent ~= char then
								if v.Name == "Hitbox" then

							dmg.Dmg(v.Parent,3,plr.Name,ss.HitAnim)
										local forward = hrp.CFrame.LookVector * 30
										dmg.Knockback(forward,v.Parent,0.25,plr)
										dmg.Stun(v.Parent,0.3)
										local meleeHit = effects.MeleeHit:Clone()
										meleeHit.Parent = hrp
										meleeHit:Emit(30)
										debris:AddItem(meleeHit,1)

								end
							end
						end
				end
		elseif m1 == 2 then
			m1 = 3
			print("last")
			coroutine.resume(coroutine.create(function()
				cd.Create(plr,"chain o' punches",3.25)
				debounce1 = false
			end))
			local anim = animator:LoadAnimation(script:FindFirstChild(m1))
			anim:Play()
			task.wait(0.1)
			local hitbox = dmg.HitboxCreate(hrp.CFrame + hrp.CFrame.LookVector * 2,Vector3.new(3,6,3),0.25)
			hitbox.Anchored = false
			local weld = Instance.new("WeldConstraint",hitbox)
			weld.Part0 = hitbox
			weld.Part1 = hrp 
			-- check for hitboxes


					task.wait(0.1)
					for _,v in pairs(checkHitbox(hitbox)) do
					if v.Parent:FindFirstChild("Humanoid") then
						if v.Parent ~= char then
							if v.Name == "Hitbox" then
							dmg.Dmg(v.Parent,3,plr.Name,ss.HitAnim)
								local forward = hrp.CFrame + hrp.CFrame.LookVector * 3
										dmg.Knockback(CFrame.lookAt(forward.Position,forward.Position + Vector3.new(0,5,0)).LookVector * 50,v.Parent,0.25,plr)
										dmg.Stun(v.Parent,0.3)
										local meleeHit = effects.MeleeHit:Clone()
										meleeHit.Parent = hrp
										meleeHit:Emit(30)
										debris:AddItem(meleeHit,1)
								end
							end
						end
					end
		end
	else
		print("debounced")
	end
end
-- Variables

local event = script.Parent.RemoteEvent
local debris = game:GetService("Debris")
local ss = game:GetService("ServerStorage")
local effects = ss.Effects
local dmg = require(ss.Dmg)
local cd = require(ss.Cooldown)
local debounce1 = false
local debounce2 = false
local debounce3 = false
local m1 = 1
local lastm1 = 3

pls halp bye… t_t

youre checking if debuonce1 is false and if it is youre setting it to true. however youre not resetting m1 to 1 anywhere in your code after it reaches 3 . this can probably mean that once m1 reaches 3 it will stay at 3 and the conditions if m1 == 1 then and elseif m1 == 2 then in your moving function will never be true againn

im writing this when its 3 am at my local time lol, brain fog is taking over me, im falling asleep on my keyboard, my solution is problily stupid

but see if this is a solution, i may be wrong

bye bye, see ya tommorow

1 Like

Thx for responding ! :3

I don’t think I have to, because whenever the script can’t find thet m1 timer which would already be gone after the cooldown here, it resets back to 1 the next time you use it.

boost… I’m for real confuzzled

Boost again… sry !!! Is this code salvageable with some bug fixes or shud I just remake it, since I’ve been taking a break?