Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Short Question]What are the differences between PlayerGui and StarterGui?

Asked by 5 years ago

I was working with GUI's for a project and I wanted to know when I should use PlayerGui's and when I should use StarterGui's. Any help is appreciated!

0
thanks NinjaManChase 226 — 5y
0
Somebody wants to gwt upvoted Carforlife1 59 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

StarterGuis hold GUI objects and LocalScripts. Children of this object are copied into the player's PlayerGui when they spawn.

PlayerGuis hold the GUI objects that will be displayed to the player. If ScreenGui is a child of a PlayerGui, then any object inside of the ScreenGui will be drawn to the player's screen. Any LocalScript will run as soon as it is inserted into a PlayerGui.

When a player first joins a game, their PlayerGui is automatically inserted into their Player object. It is good idea to use WaitForChild to access the contents of PlayerGui because the Player must load before the PlayerGui is inserted into the Player.

-- Accessing PlayerGui from a LocalScript:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

When the player's Character spawns for the first time, all of the contents of StarterGui are automatically cloned into the player's PlayerGui by default setting. As long as Players are set to respawn automatically (CharacterAutoLoads set to true) each time the Player respawns the contents of the Player’s PlayerGui will be cleared and replaced by the contents of StarterGui which are cloned into PlayerGui. Anything in a Player’s PlayerGui will be displayed on the screen for that player.

Hopefully that helped!

Ad

Answer this question