BasePlayerGui

Show Deprecated
Not Creatable

The BasePlayerGui is an abstract class that all GUI drawing storage classes inherit from.

Summary

Properties

Events

Methods


Returns a list of all GuiObject instances occupying the given point on the screen.

GetGuiObjectsInCircle(position: Vector2, radius: number): Objects  


Properties

Events

Methods

GetGuiObjectsAtPosition

This function takes a screen position and returns a list of all the GuiObject instances that are occupying that screen position.

The main use case is to get GUI objects under the player's mouse or touch inputs to do things like allow selection or highlighting. These effects can already be achieved using GuiObject.MouseEnter and GuiObject.MouseLeave but this requires the developer to track these events for their UI objects all the time even if they only need this functionality in specific circumstances.

Since the child classes of BasePlayerGui inherit this function, it can be fired by class objects such as the PlayerGui and StarterGui folders.

Parameters

The x position on the screen relative to the top left corner after the GuiInset is applied.

The y position on the screen relative to the top left corner after the GuiInset is applied.


Returns

A table of the GuiObject instances that occupy the given screen space.

Code Samples

Selecting GUIs at a Position

1local UserInputService = game:GetService("UserInputService")
2local Players = game:GetService("Players")
3
4local player = Players.LocalPlayer
5
6local playerGui = player:WaitForChild("PlayerGui")
7
8-- Create a Folder and ScreenGui to contain the highlight Frames
9local highlights = Instance.new("Folder")
10highlights.Name = "Highlights"
11highlights.Parent = playerGui
12
13local highlightsContainer = Instance.new("ScreenGui")
14highlightsContainer.Name = "Container"
15highlightsContainer.Parent = highlights
16highlightsContainer.DisplayOrder = 99999
17
18-- Creates a semi-transparent yellow Frame on top of the gui with the same AbsoluteSize and AbsolutePosition
19local function highlightAsFrame(gui)
20 local highlight = Instance.new("Frame")
21 highlight.Name = "Highlight"
22 highlight.Parent = highlightsContainer
23 highlight.Size = UDim2.new(0, gui.AbsoluteSize.X, 0, gui.AbsoluteSize.Y)
24 highlight.Position = UDim2.new(0, gui.AbsolutePosition.X, 0, gui.AbsolutePosition.Y)
25 highlight.BackgroundColor3 = Color3.fromRGB(255, 255, 10) -- Yellow
26 highlight.BackgroundTransparency = 0.75
27 highlight.BorderSizePixel = 0
28 highlight.LayoutOrder = gui.LayoutOrder - 1
29end
30
31-- Use GetGuiObjectsAtPosition to get and highlight all GuiObjects at the input's position
32local function highlightGui(input, _gameProcessed)
33 local pos = input.Position
34 local guisAtPosition = playerGui:GetGuiObjectsAtPosition(pos.X, pos.Y)
35
36 highlightsContainer:ClearAllChildren()
37
38 for _, gui in ipairs(guisAtPosition) do
39 if gui:IsA("GuiObject") then
40 highlightAsFrame(gui)
41 end
42 end
43end
44
45-- Fire highlightGui on InputBegan if input is of type MouseButton1 of Touch
46local function InputBegan(input, gameProcessed)
47 local inputType = input.UserInputType
48 local touch = Enum.UserInputType.Touch
49 local mouse1 = Enum.UserInputType.MouseButton1
50 if inputType == touch or inputType == mouse1 then
51 highlightGui(input, gameProcessed)
52 end
53end
54
55UserInputService.InputBegan:Connect(InputBegan)

GetGuiObjectsInCircle

Roblox Script Security

Parameters

position: Vector2
radius: number

Returns