ContextActionService Override issue

The problem is that, when I’m holding my mousebutton1, it works fine (as you can see from the gif below, it simply prints the mousebutton1 indicating it’s been held/fired). However, the issue arises when I hold Mousebutton1, then hold Mousebutton2 but releasing mousebutton1, instead of it just firing the mousebutton2 event, it seems to also trigger the mousebutton1 even though I let go of it.

As shown in the gif below

https://gyazo.com/5b94b49155a963cf84e1fc7b9c7deb11

code:


local function Combat(Input)
	print(Input.UserInputType)
end)


local function CombatFunction(Name, State, Object) -- function to bind it to
	if State == Enum.UserInputState.Begin then
		HoldingMouse = true
		coroutine.resume(coroutine.create(function()

		while HoldingMouse do
			--if  Debounce then
				Combat(Object)
			--end
			--task.wait()
			game:GetService("RunService").RenderStepped:Wait()
			end
		end))
	elseif State == Enum.UserInputState.End then
		HoldingMouse = false
	end
	return Enum.ContextActionResult.Pass -- return that it passed
end

--        action name   function  mobile btn           keycodes
CAS:BindAction("mouse", CombatFunction, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.MouseButton2)

Oh, you should also include the function EnumUserInputState.Changed. That function is made to detect if the inputstate have changed witihn frames, from what I believe.

How do I do this with ContextActionService?

If I had of typed it correctly, it’d probably do something in the words like this:

-- above code

if State == Enum.UserInputState.Changed then
HoldingMouse = false
end

But reading more on that, this is usually to detect mouse movement from frames.

I think a better way of doing it is this way:

local function CombatFunction(Name, State, Object) -- function to bind it to
	if State == Enum.UserInputState.Begin then
		HoldingMouse = true
		coroutine.resume(coroutine.create(function()

		while HoldingMouse do
			--if  Debounce then
				if Object.KeyCode == Enum.KeyCode.MouseButton1 and Object.KeyCode == Enum.KeyCode.MouseButton2 then
					HoldingMouse = false
				else
					Combat(Object)
					--end
					--task.wait()
					game:GetService("RunService").RenderStepped:Wait()
				end
			end
		end))
	elseif State == Enum.UserInputState.End then
		HoldingMouse = false
	end
	return Enum.ContextActionResult.Pass -- return that it passed
end

This might be scuffed, so let me know if any other problems occur.