PlayerGui
PlayerGui is a container that holds a player's UI. If a ScreenGui is a descendant, then any GuiObject inside of the ScreenGui will be drawn to the player's screen. Any LocalScript will also run if it is inserted into a PlayerGui.
When a player first joins the experience, their PlayerGui is automatically inserted into their Player object. When the player's Player.Character spawns for the first time, all of the contents of StarterGui are automatically copied into the player's PlayerGui. Note that if Players.CharacterAutoLoads is set to false, the character will not spawn and StarterGui contents will not be copied until Player:LoadCharacter() is called. If StarterGui.ResetPlayerGuiOnSpawn is set to true, then every time the player's character respawns, all of the contents of that player's PlayerGui are cleared and replaced with the contents of StarterGui.
If you need to control a player's UI container during playtime, for example to show/hide a specific ScreenGui or any of its children, access it as follows from a LocalScript:
local Players = game:GetService("Players")local player = Players.LocalPlayerlocal playerGui = player.PlayerGui
Summary
Properties
Describes the player's current screen orientation.
Sets the preferred screen orientation mode for this player, if on a mobile device.
Overrides the default selection adornment used for gamepads.
Methods
Returns the transparency of the Topbar.
Sets the transparency of the top bar.
Returns a list of all GuiObject instances occupying the given point on the screen.
Events
Fires when the transparency of the Topbar CoreGui changes.
Properties
ScreenOrientation
Sets the preferred screen orientation mode for this player, if on a mobile device.
Methods
GetTopbarTransparency
Returns the transparency of the Topbar.
Returns
Code Samples
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
print(playerGui:GetTopbarTransparency())
SetTopbarTransparency
This method sets the transparency of the top bar CoreGui. A value of 0 is completely opaque and a value of 1 is completely transparent. Values outside of the range [0, 1] are clamped. The default transparency of the topbar is 0.5.
Using the StarterGui:SetCore() method with the "TopbarEnabled" option allows you to enable/disable the entire topbar and all of its features (player list, health, etc). By contrast, this method only affects how the top bar is displayed.
Parameters
Returns
Code Samples
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
playerGui:WaitForChild("PlayerGui"):SetTopbarTransparency(0)
local Players = game:GetService("Players")
local TOPBAR_COLOR = Color3.fromRGB(0, 0, 127)
local TOPBAR_TRANSPARENCY = 0
local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
-- Hide the topbar
playerGui:SetTopbarTransparency(1)
-- Create a "Fake" replacement topbar with a ScreenGui and Frame
local screenGui = Instance.new("ScreenGui")
local frame = Instance.new("Frame")
-- Move (0, 0) to the actual top left corner of the screen, instead of under the topbar
screenGui.IgnoreGuiInset = true
-- The topbar is 36 pixels tall, and spans the entire width of the screen
frame.Size = UDim2.new(1, 0, 0, 36)
frame.BackgroundColor3 = TOPBAR_COLOR
frame.BackgroundTransparency = TOPBAR_TRANSPARENCY
frame.BorderSizePixel = 0
frame.Parent = screenGui
screenGui.Parent = playerGui
Events
TopbarTransparencyChangedSignal
Fires when the transparency of the Topbar CoreGui changes.
Parameters
Code Samples
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local function onTransparencyChanged(topbarTransparency)
print("The topbar transparency is now:", topbarTransparency)
end
playerGui.TopbarTransparencyChangedSignal:Connect(onTransparencyChanged)