Create a script that makes a part display a message above it using GUI objects

In this lesson, we will explore how to use the BillboardGui in Roblox to display text on a 3D part within the game workspace. BillboardGui is a powerful tool that allows developers to present information to players in a dynamic and visually appealing way.

1. Initializing BillboardGui:

To start, we create a new instance of BillboardGui using the Instance.new function. BillboardGui is essentially a graphical user interface that can be attached to a 3D object to display information like text, images, or icons.

local billboardGui = Instance.new("BillboardGui")

2. Setting the Adornee:

The Adornee property of BillboardGui specifies the 3D object to which the BillboardGui will be attached. In this case, we set it to a part within the game’s workspace.

billboardGui.Adornee = game.Workspace.Part

3. Adjusting Size and Position:

We can control the size and position of the BillboardGui using the Size and StudsOffset properties. The Size property determines the dimensions of the BillboardGui, while StudsOffset sets its position relative to the Adornee.

billboardGui.Size = UDim2.new(0, 200, 0, 50)
billboardGui.StudsOffset = Vector3.new(0, 2, 0)

4. Creating a TextLabel:

To display text within the BillboardGui, we use a TextLabel. A TextLabel is a UI element that can hold and display text.

local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "Holik Studios"
textLabel.TextColor3 = Color3.new(0, 0, 1) -- Set text color to blue
textLabel.BackgroundTransparency = 1 -- Make the background transparent

5. Setting Parent-Child Relationships:

The TextLabel is set as a child of the BillboardGui, and the BillboardGui is set as a child of the specified part in the workspace. This establishes the hierarchy necessary for the components to be rendered properly.

textLabel.Parent = billboardGui
billboardGui.Parent = game.Workspace.Part

Conclusion:

By following these steps, you can create a visually engaging display of information in your Roblox game. BillboardGui offers a flexible and customizable way to communicate with players, making it a valuable tool for enhancing the user experience. Experiment with different properties and settings to achieve the desired look and feel for your in-game UI elements.