LMB Combo Not Cycling

  1. I’m trying to make a local script so that when a player presses mouse button 1, they do a light attack, then after that, if they press mouse button 1 again they do a medium attack, then if they press mouse button 1 once more it does a heavy attack.

  2. The issue is that after pressing mouse button 1 once, upon pressing it again it does not do the medium attack instead it repeats the light attack.

  3. I have re-read the code and how to use elseif statements but I have no idea what to do to fix this issue.

inputService.InputEnded:Connect(function(input, gameProcessedEvent)
	local lightDebo = false
	local mediumDebo = false
	if debounceLMB == false then
		if not gameProcessedEvent then
			if input.UserInputType == Enum.UserInputType.MouseButton1 then
				if lightDebo == false and mediumDebo == false then
					lightDebo = true
					print("LIGHT FIRED")
				elseif lightDebo == true and mediumDebo == false then
					lightDebo = false
					mediumDebo = true
					print("MEDIUM FIRED")
				elseif mediumDebo == true and lightDebo == false then
					lightDebo = false
					mediumDebo = false
					debounceLMB = true
					print("HEAVY FIRED")
				if debounceLMB == true then
					debounceLMB = false

Your code’s logic is flawed.

Firstly your variables lightDebo and mediumDebo are both local to the scope of the function, so the moment the function ends, they no longer exist. Secondly, you set their values to false at the beginning of the function, so each time an input occurs, it resets.

To fix this, simply change the order of the first 3 lines like so:

local lightDebo = false
local mediumDebo = false
inputService.InputEnded:Connect(function(input, gameProcessedEvent)

This moves the variables into a broader scope in the script, and allows them to persist between function calls. This way they also don’t reset on each call.

I hope this helps!

1 Like

oh my gosh thanks so much that was such a simple solution :sob: