How to detect if a player clicks off the ui?

Hello developers!

So im currently making my own custom leaderboard ui and i would like the “player viewer” to disappear if the player clicks anywhere off it.

So my question is, is there any way to detect if the player clicks but doesnt click any of the buttons available. Basically functioning like the default leaderboard system (you view the player but if you click anywhere else it auto closes)

image

2 Likes

Check for a click and get the GUI objects at the mouse’s position:

UIS.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
      local atPos = PlayerGui:GetGuiObjectsAtPosition(input.Position.X, input.Position.Y)
     if atPos == 0 then
-- your code
       end
    end
end)

My bad I accidentally put “MouseClick” when it should’ve been “MouseButton1” for the UserInputType

3 Likes

I appreciate the support! thank you.

1 Like

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