UserInputService.InputBegan - MouseButton1 failing to trigger the signal

Hello all,

Recently, I’ve reworked some old code in order to sort one issue out.

This issue was pretty clear:

  • The MouseButton1 input would not trigger the InputBegan event of the UserInputService after a random amount of time.

As you can see by the large amount of prints and warns I have added, I attempted to work out where the issue originated from. However, after sometime every input except MouseButton1 would trigger the signal. Is there any known reason for this?

It is important to note that the following code is in a LocalScript and is the child of a Tool:

userInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
	if gameProcessedEvent then
		return
	end
	
	print(input.KeyCode, input.UserInputType) -- Every input except MouseButton1 printed
	
	if input.KeyCode == Enum.KeyCode.R then
		isKeyHeld = true
		
		return
	end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		print(`MouseButton1 fired...`)
		
		if debounce then
			warn(`Debounce`)
			return
		end
		
		if visual.Parent ~= workspace then
			warn(`Parent does not exist.`)
			return
		end
		
		debounce = true
		warn(`Firing server...`)
		remoteEvent:FireServer(visual.Spawn:GetPivot())
		warn(`Server fired.`)
		
		task.delay(5, function()
			debounce = false
		end)
	end
end)

Why does your function have “input: InputObject, gameProcessedEvent: boolean”? Try just using “input, gameProcessedEvent”

Why would I do that? All these do is expose the intellisense for me.

Alright, so. I tried something and it printed out MouseButton1.

https://gyazo.com/e5a4ed6e21f61f106c08aeea3cdef8d5

Here is the code:

local uis = game.UserInputService
uis.InputBegan:Connect(function(input: InputObject, gpe: boolean)
 if gpe then return end	
 local Type, Code = input.UserInputType.Name, input.KeyCode.Name	
 print(Type)
 print(Code)
	
end)

My issue is the inconsistency. My code works for a while, then it just randomly drops MouseButton1 inputs from firing the signal.

There is no error related to this, either, it just randomly stops whilst continuing to listen to every other input.

Sorry, i misunderstood. It stop printing MouseButton1 after a spam or when you press mouse over the time it stop to print MouseButton1?

It stops after a random period of time.

Do you happen to have any UI covering the screen?

There is nothing that’d be causing the gameProcessedEvent check to block the input code going any further.

i tried spamming it with an autoclicker and MouseButton1 were printing. The only lines i werent using was:

if visual.Parent ~= workspace then
	warn(`Parent does not exist.`)
	return
end

and

remoteEvent:FireServer(visual.Spawn:GetPivot())

Maybe visual.Parent or visual create your issue

It isn’t that, it doesn’t even print the following:

print(input.KeyCode, input.UserInputType)

Have you try creating another local script and copy paste the code into the new one? sometimes, it saved me

Does your Tool have a Handle? And if not maybe setting the property RequiresHandle to false fixes this?

No. I doubt this will change anything as the code works at first and randomly stops for the signal input I need.

I can try that, however it is actually a module we place into the game with InsertService when we need it, as opposed to it permanently being there.

Then sorry, i have no other idea about your problem. Maybe this is a roblox issue but i am not sure. Hope you will find a solution!

If a tool does not have a handle it will stop the Tool.Activated signal from firing, maybe this stops InputBegan for your mouse button 1 too. But you’re probably right.