In Roblox Lua scripting, a GUI (Graphical User Interface) refers to any visual element that players can see and interact with in the game. GUIs are created using Instances derived from the GuiBase class and are typically used for menus, HUDs (Heads-Up Displays), dialogs, and other interactive elements.
Common GUI Types in Roblox:
ScreenGui – The container for all GUIs that appear on the player's screen.
Frame – A rectangular container for other GUI elements.
TextLabel – Displays static text.
TextButton – A clickable button with text.
ImageLabel – Displays an image.
ImageButton – A clickable button with an image.
ScrollingFrame – A frame that allows scrolling content.
TextBox – Allows players to input text.
ViewportFrame – Displays a 3D view inside a GUI.
Example: Creating a Simple GUI
lua
-- Create a ScreenGui (parented to the player's PlayerGui)
local player = game.Players.LocalPlayer
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = player:WaitForChild("PlayerGui")
-- Create a Frame inside the ScreenGui
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0, 200, 0, 100) -- Width: 200, Height: 100
frame.Position = UDim2.new(0.5, -100, 0.5, -50) -- Centered
frame.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2) -- Dark gray
frame.Parent = screenGui
-- Add a TextLabel inside the Frame
local label = Instance.new("TextLabel")
label.Size = UDim2.new(1, 0, 1, 0) -- Full frame size
label.Text = "Hello, Roblox!"
label.TextColor3 = Color3.new(1, 1, 1) -- White text
label.TextScaled = true -- Auto-scale text
label.Parent = frame
-- Add a TextButton inside the Frame
local button = Instance.new("TextButton")
button.Size = UDim2.new(0.5, 0, 0.3, 0) -- Half width, 30% height
button.Position = UDim2.new(0.25, 0, 0.7, 0) -- Centered at bottom
button.Text = "Click Me!"
button.Parent = frame
-- Make the button do something when clicked
button.MouseButton1Click:Connect(function()
print("Button clicked!")
label.Text = "You clicked the button!"
end)
Key Notes:
UDim2 is used for positioning and sizing GUIs (e.g., UDim2.new(0.5, 0, 0.5, 0) means 50% from the left and top).
Parent determines where the GUI appears (e.g., PlayerGui for player-specific GUIs).
MouseButton1Click is an event for detecting button clicks.
Would you like help with a specific GUI feature or functionality? 😊