Making an M1 System, but left clicks just keep breaking

Im trying to make a left click combo system (Similar to ABA) but Im having issues with the left clicks randomly breaking and letting the user spam. I tried this:

local player = game.Players.LocalPlayer
local chr = player.CharacterAdded:Wait() 
local hum = chr:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
local check = Instance.new("NumberValue", hum)
local p = 0
local db = 0
print("loaded!")
local function air(toggle)
	if toggle == "on" then
		local bv = Instance.new("BodyVelocity",chr.HumanoidRootPart) 
		bv.Velocity = Vector3.new(0,0,0)
		bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	elseif toggle == "off" then
		chr.HumanoidRootPart:FindFirstChild("BodyVelocity"):Destroy()
	end
end
local function punch(ID)
	p += 1
	check.Value = p
	print(p)
	local animplay = game.ReplicatedStorage.Animations:FindFirstChild("Punch"..p)
	local track = hum:LoadAnimation(animplay)
	track.Priority = "Action"
	track:Play()
	if p == 4 then
		p = 0
		hum.WalkSpeed = 5
		hum.JumpPower = 0
		air("on")
		task.wait(1.2)
		hum.WalkSpeed = 16
		hum.JumpPower = 50
		air("off")
		db = 0
		return db, p
	end
	if p ~= 4 then
		hum.WalkSpeed = 5
		hum.JumpPower = 0
		air("on")
		task.wait(0.8)
		air("off")
		hum.WalkSpeed = 16
		hum.JumpPower = 50
		db = 0
		print("cdoff")
	end
	if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
		punch()
	end
	return db,p
	
end


uis.InputBegan:Connect(function(input, proc)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if proc == false then	
			if db == 0 then
				db = 1
				print("punch")
				punch()
				
			end
			
		end
	end 
end)

(Im only a few weeks in rn.)
The check var isn’t used so ignore that,

Have you tried to “put” a debounce?

If my reply has nothing to do with your question, please then explain

1 Like

db is debounce, I think Im not using it correctly.

You used debounce as a “0”. Debounce is supposed to be a boolean.

Do you want me to try to correct it?

I don’t think that using a boolean or number would make it any different though, because they are still being used in the same manner, to check if there’s a cooldown on something, but if you think it would fix this glitch Im having, go at it :+1:

I detected that at the end the debounce does the effect. But it think it’s the “elseif”. It’s “if” instead of “elseif”

local player = game.Players.LocalPlayer
local chr = player.CharacterAdded:Wait() 
local hum = chr:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
local check = Instance.new("NumberValue", hum)
local p = 0
local db = false
print("loaded!")
local function air(toggle)
	if toggle == "on" then
		local bv = Instance.new("BodyVelocity",chr.HumanoidRootPart) 
		bv.Velocity = Vector3.new(0,0,0)
		bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	elseif toggle == "off" then
		chr.HumanoidRootPart:FindFirstChild("BodyVelocity"):Destroy()
	end
end
local function punch(ID)
	p += 1
	check.Value = p
	print(p)
	local animplay = game.ReplicatedStorage.Animations:FindFirstChild("Punch"..p)
	local track = hum:LoadAnimation(animplay)
	track.Priority = "Action"
	track:Play()
	if db == false and p == 4 then
		p = 0
            db = true
		hum.WalkSpeed = 5
		hum.JumpPower = 0
		air("on")
		task.wait(1.2)
		hum.WalkSpeed = 16
		hum.JumpPower = 50
		air("off")
		db = false
		return db, p
	elseif db == false and p ~= 4 then
db = true
		hum.WalkSpeed = 5
		hum.JumpPower = 0
		air("on")
		task.wait(0.8)
		air("off")
		hum.WalkSpeed = 16
		hum.JumpPower = 50
		db = false
		print("cdoff")
end
	if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
		punch()
	end
	return db,p
	
end


uis.InputBegan:Connect(function(input, proc)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if proc == false then	
			punch()
			
		end
	end 
end)

From what I can see, you have this like

if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
		punch()
	end

in the punch function. Wouldn’t that possibly activate WHILE the inputBegan event also happens, which would call the function twice and break the timing?

Oh, I didn’t notice that! That’s another reason that’s not working

1 Like