GuiService
*เนื้อหานี้จะพร้อมใช้งานในภาษาที่คุณเลือกในเร็วๆ นี้
GuiService allows developers to control what GuiObject is currently being selected by the gamepad navigator, as well as check if Roblox's main menu is currently open.
สรุป
คุณสมบัติ
If activated, the Select button on a Gamepad or Backslash will automatically set a GUI as the selected object.
Toggles whether or not objects in the CoreGui can be navigated using a Gamepad.
Used to enable and disable the default controller GUI navigation.
Returns true if any menu of CoreGui is open.
Gets the user's preferred transparency as a number between 0 and 1, which indicates how opaque they want the backgrounds of certain UI elements to be. The recommended usage is as a multiplier of an element's BackgroundTransparency. Defaults to 1.
Returns true if the user has enabled reduced motion. Defaults to false.
Sets the GuiObject currently being focused on by the GUI Navigator (used for Gamepads).
Used to determine the absolute size and position of unobstructed area within top bar space.
Used to enable and disable touch controls and touch control display UI. Defaults to true.
วิธีการ
Closes the Inspect Menu, if open.
Checks if the player Emotes menu is open.
Returns whether or not the gameplay paused notification has been disabled by the developer.
Returns two Vector2 values representing the inset of user GUIs in pixels, from the top left corner of the screen and the bottom right corner of the screen respectively.
Returns whether the Inspect and Buy menu functionality is enabled.
Allows a developer to bring up the Inspect menu showing the assets listed in this HumanoidDescription object.
Allows the Inspect Menu to appear showing the user that has the given UserId.
Returns true if the client is using the ten foot interface, which is a special version of Roblox's UI, exclusive to consoles. This is the only guaranteed way to verify if the user is on a console or not.
Set GuiService.SelectedObject to a child of provided instance selectionParent that is PlayerGui or its descendants.
Opens or closes the player Emotes menu.
Allows developers to disable the built-in notification when a players gameplay is paused.
Allows developers to enable or disable default Inspect and Buy functionality.
อีเวนต์
Fires when the user closes the Roblox coregui escape menu.
Fires when the user opens the Roblox coregui escape menu.
คุณสมบัติ
AutoSelectGuiEnabled
If activated, the Select button on a Gamepad or Backslash will automatically set a GUI as the selected object. Turning this off will mean that Gui navigation will still work if GuiService.GuiNavigationEnabled is enabled but you will have to set GuiService.SelectedObject manually to start Gui navigation.
CoreGuiNavigationEnabled
Toggles whether or not objects in the CoreGui can be navigated using a Gamepad.
PreferredTextSize
PreferredTransparency
Gets the user's preferred transparency as a number between 0 and 1, which indicates how much more opaque they want the background of UI elements to be. Defaults to 1.
This return value reflects a setting which can be set from the user's side in either the app settings or within the in-experience settings menu via Background Transparency. The default value is 1, indicating that the user prefers the default background transparency. The lowest value is 0, indicating that the user prefers backgrounds to be completely opaque, improving readability and contrast for affected UI. Multiplying an element's GuiObject.BackgroundTransparency with the value returned from PreferredTransparency is the recommended way to use this setting; backgrounds will become more opaque as PreferredTransparency approaches 0. This should be used with Object:GetPropertyChangedSignal() so that it automatically updates when the user changes their preferred transparency.
ตัวอย่างโค้ด
local DEFAULT_TRANSPARENCY = 0.5
local frame = script.Parent
local function setBackgroundTransparency()
frame.BackgroundTransparency = DEFAULT_TRANSPARENCY * GuiService.PreferredTransparency
end
GuiService:GetPropertyChangedSignal("PreferredTransparency"):Connect(setBackgroundTransparency)
setBackgroundTransparency()
ReducedMotionEnabled
Returns true if the user has enabled reduced motion. Defaults to false.
This return value reflects a setting which can be set from the user's side in either the app settings or within the in-experience settings menu via Reduce Motion. A value of true indicates that the user wants motion effects and animations to be reduced or completely removed.
ตัวอย่างโค้ด
local DEFAULT_TRANSPARENCY = 0.5
local frame = script.Parent
local endPosition = UDim2.fromScale(0.5, 0.8)
if GuiService.ReducedMotionEnabled then
frame.Position = endPosition
else
local moveTweenInfo = TweenInfo.new(0.5)
local moveTweenProps = {
Position = endPosition
}
local moveTween = TweenService:Create(frame, slideInTweenInfo, slideInTweenProps)
moveTween:Play()
end
SelectedObject
Sets the GuiObject currently being focused on by the GUI Navigator (used for Gamepads). This may reset to nil if the object is off-screen.
This property is changed by the GuiObject.SelectionGained and GuiObject.SelectionLost events.
If you would like to determine when this property changes without tracking the SelectionGained and SelectionLost events for all GUI elements, you can use the Changed event.
ตัวอย่างโค้ด
local GuiService = game:GetService("GuiService")
local function printChanged(value)
if value == "SelectedObject" then
print("The SelectedObject changed!")
end
end
GuiService.Changed:Connect(printChanged)
TopbarInset
Returns a Rect object representing the unoccupied area between the Roblox left-most controls and the edge of the device safe area.
The value is dynamic and can be expected to change based on the visibility of UI controls such as changing the local player's Health property, usage of StarterGui:SetCoreGuiEnabled(), changing the size and position of Roblox UI Controls, and/or others. For this reason, it's recommend that you detect and react to changes of this property with Object:GetPropertyChangedSignal().
ตัวอย่างโค้ด
local GuiService = game:GetService("GuiService")
local Players = game:GetService("Players")
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.Parent = Players.LocalPlayer.PlayerGui
local frame = Instance.new("Frame")
frame.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
frame.Parent = screenGui
GuiService:GetPropertyChangedSignal("TopbarInset"):Connect(function()
local inset = GuiService.TopbarInset
frame.Size = UDim2.new(0, inset.Width, 0, inset.Height)
frame.Position = UDim2.new(0, inset.Min.X, 0, inset.Min.Y)
end)
TouchControlsEnabled
Used to enable and disable touch controls and touch control display UI. Defaults to true.
วิธีการ
CloseInspectMenu
This function closes the Inspect Menu, if open, when run from a LocalScript.
See also:
- Avatar Inspect Menu, an article providing a more detailed explanation of the Inspect and Buy feature and how it works
- GuiService:InspectPlayerFromHumanoidDescription(), allows a developer to bring up the Inspect menu showing the assets listed in this HumanoidDescription object. This is especially useful when what is being worn on a player's avatar on the Roblox platform is not necessarily the same as their in-game appearance
- GuiService:InspectPlayerFromUserId(), allows the Inspect Menu to appear showing the user that has the given UserId. This is especially useful when you want to inspect players who aren't in the current game
ส่งค่ากลับ
GetEmotesMenuOpen
Returns a boolean indicating whether or not the player Emotes menu is open.
Developers can open or close the Emotes menu by calling the GuiService:SetEmotesMenuOpen() function.
ส่งค่ากลับ
Indicates whether the Emotes menu is open.
GetGameplayPausedNotificationEnabled
This function returns whether or not the gameplay paused notification has been disabled by the developer.
Developers can enable or disable the notification by calling the GuiService:SetGameplayPausedNotificationEnabled() function.
See also:
- Workspace.StreamingIntegrityMode and Enum.StreamingIntegrityMode for more details on when gameplay is paused.
ส่งค่ากลับ
Whether or not the gameplay paused notification has been disabled.
GetGuiInset
Returns two Vector2 values representing the inset of user GUIs in pixels, from the top left corner of the screen and the bottom right corner of the screen respectively.
The inset values supplied by this function only take effect on ScreenGuis that have their IgnoreGuiInset property set to false.
ส่งค่ากลับ
A tuple of two Vector2 values describing the current specified Gui Inset.
GetInspectMenuEnabled
This function returns whether the Inspect and Buy menu functionality is currently enabled. The feature is enabled by default and can be set using the GuiService:SetInspectMenuEnabled() function.
See also:
- Avatar Inspect Menu, an article providing a more detailed explanation of the Inspect and Buy feature and how it works
- GuiService:InspectPlayerFromHumanoidDescription(), allows a developer to bring up the Inspect menu showing the assets listed in this HumanoidDescription object. This is especially useful when what is being worn on a player's avatar on the Roblox platform is not necessarily the same as their in-game appearance
- GuiService:InspectPlayerFromUserId(), allows the Inspect Menu to appear showing the user that has the given UserId. This is especially useful when you want to inspect players who aren't in the current game
ส่งค่ากลับ
A boolean indicating whether the Inspect Menu feature is enabled.
InspectPlayerFromHumanoidDescription
This function allows a developer to bring up the Inspect menu showing the assets listed in this HumanoidDescription object.
This allows further customization with what is shown in the Inspect Menu when players inspect other players in your game. If your game modifies what the players are wearing, you can instead give the Inspect Menu a HumanoidDescription object that represents what a player is wearing and those items will be shown. You should pass a name as well to represent the name of the player that will be inspected.
See also:
- Avatar Inspect Menu, an article providing a more detailed explanation of the Inspect and Buy feature and how it works
- GuiService:SetInspectMenuEnabled(), allows developers to enable or disable default Inspect and Buy functionality
- GuiService:InspectPlayerFromUserId(), allows the Inspect Menu to appear showing the user that has the given UserId. This is especially useful when you want to inspect players who aren't in the current game.
พารามิเตอร์
A HumanoidDescription object that contains the assets to show in the Inspect menu.
The name of the player being Inspected to show in the Inspect menu.
ส่งค่ากลับ
ตัวอย่างโค้ด
local GuiService = game:GetService("GuiService")
local humanoidDescription = Instance.new("HumanoidDescription")
humanoidDescription.HatAccessory = "3339374070"
humanoidDescription.BackAccessory = "3339363671"
GuiService:InspectPlayerFromHumanoidDescription(humanoidDescription, "MyPlayer")
InspectPlayerFromUserId
This function allows the Inspect Menu to appear showing the user that has the given UserId. This is especially useful when you want to inspect players who aren't in the current game.
This shows the same information as the "Currently Wearing" tab on the specified user's profile.
See also:
- Avatar Inspect Menu, an article providing a more detailed explanation of the Inspect and Buy feature and how it works
- GuiService:SetInspectMenuEnabled(), allows developers to enable or disable default Inspect and Buy functionality. This is especially useful when what is being worn on a player's avatar on the Roblox platform is not necessarily the same as their in-game appearance
- GuiService:InspectPlayerFromHumanoidDescription(), allows a developer to bring up the Inspect menu showing the assets listed in this HumanoidDescription object
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
local GuiService = game:GetService("GuiService")
GuiService:InspectPlayerFromUserId(772462)
IsTenFootInterface
Returns true if the client is using the ten foot interface, which is a special version of Roblox's UI, exclusive to consoles. This is the only guaranteed way to verify if the user is on a console or not.
ส่งค่ากลับ
Select
When Select is called on an instance selectionParent that is PlayerGui or a descendant of PlayerGui, the engine searches all available selectable, visible and on-screen GuiObjects that are descendants of selectionParent and sets the GuiService.SelectedObject to the GuiObject with the smallest GuiService.SelectionOrder.
พารามิเตอร์
The parent of selection whose descendants are searched.
ส่งค่ากลับ
ตัวอย่างโค้ด
local DEFAULT_TRANSPARENCY = 0.5
local frame = script.Parent
local function setBackgroundTransparency()
frame.BackgroundTransparency = DEFAULT_TRANSPARENCY * GuiService.PreferredTransparency
end
GuiService:GetPropertyChangedSignal("PreferredTransparency"):Connect(setBackgroundTransparency)
setBackgroundTransparency()
SetGameplayPausedNotificationEnabled
This method allows developers to disable the built-in notification when a players gameplay is paused. They can then add in their own UI if they wish to customize it.
Developers can query whether the notification is enabled by calling the GuiService:GetGameplayPausedNotificationEnabled() function.
See also:
- Workspace.StreamingIntegrityMode and Enum.StreamingIntegrityMode for more details on when gameplay is paused.
พารามิเตอร์
Whether or not the built-in notification GUI is disabled.
ส่งค่ากลับ
SetInspectMenuEnabled
This function allows developers to enable or disable default Inspect and Buy functionality. This is useful when you want to disable the feature in your game, entirely or during certain parts of your game (such as a cutscene). The feature is enabled by default.
The code sample below demonstrates how to disable the Inspect Menu for your game:
local GuiService = game:GetService("GuiService")GuiService:SetInspectMenuEnabled(false)
See also:
- Avatar Inspect Menu, an article providing a more detailed explanation of the Inspect and Buy feature and how it works
- GuiService:InspectPlayerFromHumanoidDescription(), allows a developer to bring up the Inspect menu showing the assets listed in this HumanoidDescription object. This is especially useful when what is being worn on a player's avatar on the Roblox platform is not necessarily the same as their in-game appearance
- GuiService:InspectPlayerFromUserId(), allows the Inspect Menu to appear showing the user that has the given UserId. This is especially useful when you want to inspect players who aren't in the current game
พารามิเตอร์
A boolean indicating whether to enable or disable the Inspect Menu feature.
ส่งค่ากลับ
อีเวนต์
MenuClosed
Fires when the user closes the Roblox coregui escape menu.
MenuOpened
Fires when the user opens the Roblox coregui escape menu.