Mobile button not working as intended

Hello. I am trying to set up mobile support for my game and I am having an issue.

What I want is to detect holding and releasing the mobile button (created by contextactionservice) but it is not working. Here is the code:

local connection
local function leftClick()
	local db = false
	UIS.InputBegan:Connect(function(input)
		if db then return end
		if input.UserInputState == Enum.UserInputState.Begin then
			MouseLeftClick.Value = true
			db = true
			task.delay(.1, function()
				db = false
			end)
	
		 connection = input.Changed:Connect(function()
			if input.UserInputState == Enum.UserInputState.End then
				MouseLeftClick.Value = false
				db = true
				task.delay(.1, function()
					db = false
				end)
				connection = nil
			end
		end)
		end
	end)
end

CAS:BindAction("L", leftClick, true)
CAS:SetTitle("L", "L")

Right now, it actually detects hold and release, but after I hit the button once, it starts to take ANY action as holding down the button, like touching the screen to walk. How can I fix that?

this could work, if not, let me know:

local connection

local function onInput(input, gameProcessed)
    if gameProcessed then
        return
    end

    if input.UserInputType == Enum.UserInputType.Touch then
        if input.UserInputState == Enum.UserInputState.Begin then
            MouseLeftClick.Value = true
        elseif input.UserInputState == Enum.UserInputState.End then
            MouseLeftClick.Value = false
        end
    end
end

local function leftClick(actionName, inputState, inputObject)
    if inputState == Enum.UserInputState.Begin then
        MouseLeftClick.Value = true
    elseif inputState == Enum.UserInputState.End then
        MouseLeftClick.Value = false
    end
end

CAS:BindAction("L", leftClick, false, Enum.KeyCode.ButtonL)

UIS.InputBegan:Connect(onInput)
UIS.InputEnded:Connect(onInput)