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)
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)
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.