Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i detect when Player clicks but not on gui?

Mouse.Button1Down:Connect(function()
print("Clicked")
end)

How would I make this not work when player clicks on a gui?

1 answer

✓ Accepted answer

For this you'd have to use UserInputService, though you'll have to use InputObject.UserInputType to get the Enum path for Click-Input. The reason behind using a different Service is because this particular one passes the GameProcessed Bool that allows us to primarily reject Click-Input from ClickDetectors and GUI's

UserInputService.InputBegan:Connect(function(InputObject, GameProcessed)
   if (InputObject.UserInputType = Enum.UserInputType.MouseButton1) then
      if not (GameProcessed) then
       print("Player Left-Clicked")
      end
   end
end)

It's a simple as that.

Hope this helps! if so don't forget to accept this answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.