PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Create 3D GUI Elements

Create 3D GUI Elements

Jun 23 2018, 2:01 AM PST

Problem

You want to create custom 3D GUI like the health bar above character’s heads or like the names that float above character’s heads.

Solution

Use the BillboardGui as the container instead of ScreenGui.

repeat wait() until game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild('Head')
 
script.Parent.Adornee = game.Players.LocalPlayer.Character.Head
script.Parent.TextLabel.Text = string.reverse(game.Players.LocalPlayer.Name)

Discussion

Create a BillboardGui in the StarterGui and inside of there put a TextLabel and a LocalScript. The BillboardGui Size property should be set to {.5, 0, .5, 0} and the StudsOffset should be set to (0, 2, 0).

In our script we can use some of the LocalScript shortcuts I had mentioned previously. Instead of saying script.Parent.Parent.Parent to get to the Player directory, we can just say game.Players.LocalPlayer. We wait until the LocalPlayer (the user using the GUI) has a Character and Head, then we set the Adornee of the BillboardGui to that Head. We then take the TextLabel and set its text to the reverse of the new of the LocalPlayer.

The result is the reverse of your name appearing above your head. Do note that all GUI is local meaning that it appears only to the Player using the GUI. Therefore the text hovering above your head is only seen to you. Other players see their reversed names hovering over their respective heads, but they cannot set each others.

Also note that at the time of this writing BillboardGui is still being developed. Therefore there are bugs with it. One of these is when you zoom out the text is scaled up instead of the expected behavior of scaling down.

Tags:
  • gui-effect