Easy Written By GalaxyGourmet

Custom Player Overhead Gui Created on: 15-01-2020

Use Clone() to give the player their own custom overhead Gui.

Setting it Up

To give the player their own overhead Gui, you'll have to make it first. Follow the steps below to set it up correctly.

  1. Insert a BillboardGui in ReplicatedStorage. Insert a TextLabel in the BillboardGui you inserted in ReplicatedStorage. Name the BillboardGui to "NameDisplay" (You don't actually need to do this, but you'll have to make additional changes to the script if you don't). Change the properties of the BillboardGui and TextLabel to your liking.

Once you've done that, you should be good to go.

The Script

To begin the scripting part of this tutorial, you must insert a normal Script inside StarterCharacterScripts. Then open it up.

We'll first make a variable for ReplicatedStorage to keep the script organized.

local replicatedStorage = game.ReplicatedStorage

Next, we'll clone the BillboardGui in ReplicatedStorage. We'll also have to make a variable for that too.

local replicatedStorage = game.ReplicatedStorage
local clone = replicatedStorage.NameDisplay:Clone()
 --Remember to change "NameDisplay" to the name of the BillboardGui if you changed it!

About Clone()

Before we continue with the script, you should know a bit about Clone() and what it does.

Clone() is a function that can used for pretty much any object in your game. That means you can use Part:Clone(), ScreenGui:Clone(), and you probably get it by now. Clone() basically duplicated the object that you cloned. Clones' parent is set to nil by default, so you'll still have to change the parent too.

If you assign a variable for the cloned object, you can change the clone's properties like so:

local clone = game.Workspace.Part:Clone()

clone.Parent = game.Workspace
clone.CanCollide = false

It can be pretty useful if you know what to do with it.

Back to the Script

Now that you have a little insight of Clone(), we can now use it to finish the script. As mentioned above, cloned objects have their parent set to nil by default. However, we're of couse going to change it's parent, which will be one of the players parts. Insert the following into the script.

local replicatedStorage = game.ReplicatedStorage
local clone = replicatedStorage.NameDisplay:Clone()
 --Remember to change "NameDisplay" to the name of the BillboardGui if you changed it!

clone.Parent = script.Parent.Head

Since this script will be in the player's character, we can simply just write "script.Parent.BodyPartName" You can change it's parent to another body part, like Torso or HumanoidRootPart, but for this tutorial, it will be in the head.

Now we have to change the text for the TextLabel so it matches the player's name. Insert the following in the script.

local replicatedStorage = game.ReplicatedStorage
local clone = replicatedStorage.NameDisplay:Clone()
--Remember to change "NameDisplay" to the name of the BillboardGui if you changed it!

clone.Parent = script.Parent.Head
clone.TextLabel.Text = script.Parent.Name
--Remember to change "TextLabel" to the name of the TextLabel if you changed it!

Because the parent of the script will be in the player's character, we can just write "script.Parent.Name" for the text.

Now test the game. If you've done everything correctly, you should see your name above yourself.



Final Script

Make sure to read the beggining of the tutorial before reading our final script.

--Remember, this must be a normal Script inserted in StarterCharacterScripts.
local replicatedStorage = game.ReplicatedStorage
local clone = replicatedStorage.NameDisplay:Clone() 
--Remember to change "NameDisplay" to the name of the BillboardGui if you changed it!

clone.Parent = script.Parent.Head
clone.TextLabel.Text = script.Parent.Name
--Remember to change "TextLabel" to the name of the TextLabel if you changed it!

Easy Written By GalaxyGourmet

See GalaxyGourmet's profile on Roblox

Discussion