PlayerGui

Show Deprecated
Not Creatable
Player Replicated

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.LocalPlayer
local playerGui = player.PlayerGui

Summary

Properties

Methods

Methods inherited from BasePlayerGui

Events

Properties

CurrentScreenOrientation

Read Only
Not Replicated
Read Parallel

Describes the player's current screen orientation.

ScreenOrientation

Read Parallel

Sets the preferred screen orientation mode for this player, if on a mobile device.

SelectionImageObject

Read Parallel

Overrides the default selection adornment used for gamepads. For best results, this should point to a GuiObject.

Methods

GetTopbarTransparency

Deprecated

Returns the transparency of the Topbar.


Returns

Code Samples

PlayerGui:GetTopbarTransparency

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
print(playerGui:GetTopbarTransparency())

SetTopbarTransparency

void
Deprecated

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

transparency: number

Returns

void

Code Samples

PlayerGui:SetTopbarTransparency

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
playerGui:WaitForChild("PlayerGui"):SetTopbarTransparency(0)
Custom Topbar Style

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

Deprecated

Fires when the transparency of the Topbar CoreGui changes.

Parameters

transparency: number

Code Samples

PlayerGui.TopbarTransparencyChangedSignal1

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)