Help with clicking anywhere

I got this dumb issue which I could not find anything about.

local function OnScreenClicked(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		ReplicatedStorage.Remotes.Strength:FireServer()
	end
end

I have this code, which runs a function when a key is pressed. If you left mouse click you gain strength. However there is an issue that I cannot click any UI buttons because it will give me strength instead of clicking it. Now this makes sense since it just detects left mouse clicks. My question is, is there any way to easily detect this and check something like PressedButton or something or do I have to make some weird calculation to see if the mouse is on a frame each time.

InputBegan or any other input event gives a second parameter: the gameProcessedEvent. This will be true if they clicked any Gui button.
So you could try this:

local function OnScreenClicked(input, processed)
    if processed then return end --added this line
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		ReplicatedStorage.Remotes.Strength:FireServer()
	end
end

Thank you this is exactly what I was searching for.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.