Below is a LocalScript you can drop into StarterPlayerScripts that will automatically create the lobby UI for you. This script builds a ScreenGui that contains a BillboardGui “floating” above a part (named “GUIAnchor” in Workspace) and sets up basic elements like the title, player count, countdown status, and a leave button. Later, our other scripts (like the ServerScript “LobbyManager”) will talk to this UI via RemoteEvents. You can copy and paste this code into a new LocalScript, then run the game to see the GUI pop into existence.
Steps to Set Up the Lobby UI Automatically:
Setup Your Place:
In Workspace, create (or ensure you have):
A Part named "GUIAnchor" (this will be the attachment point for the floating UI, so position it above your teleport pad).
In StarterPlayer → StarterPlayerScripts, add a new LocalScript named "LobbyGUIHandler".
Paste This Code into the LocalScript:
lua
-- LobbyGUIHandler (LocalScript)
-- This script creates the lobby UI automatically and handles updates from the server.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
------------------------------
-- Create the ScreenGui
------------------------------
local lobbyGui = Instance.new("ScreenGui")
lobbyGui.Name = "LobbyGui"
lobbyGui.ResetOnSpawn = false
lobbyGui.Parent = playerGui
------------------------------
-- Create the BillboardGui that will float above GUIAnchor
------------------------------
local teleportDisplay = Instance.new("BillboardGui")
teleportDisplay.Name = "TeleportDisplay"
teleportDisplay.Size = UDim2.new(0, 300, 0, 150)
teleportDisplay.AlwaysOnTop = true
teleportDisplay.ExtentsOffset = Vector3.new(0, 3, 0) -- adjust offset as needed
teleportDisplay.Parent = lobbyGui
-- Wait for the GUIAnchor in the workspace and attach to it.
local guiAnchor = workspace:WaitForChild("GUIAnchor")
teleportDisplay.Adornee = guiAnchor
------------------------------
-- Create a Frame to serve as the background of the GUI
------------------------------
local frame = Instance.new("Frame")
frame.Parent = teleportDisplay
frame.Size = UDim2.new(1, 0, 1, 0)
frame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
frame.BorderSizePixel = 2
frame.BorderColor3 = Color3.fromRGB(255, 255, 255)
------------------------------
-- Create the Title label
------------------------------
local title = Instance.new("TextLabel")
title.Name = "Title"
title.Parent = frame
title.Size = UDim2.new(1, 0, 0.3, 0)
title.BackgroundTransparency = 1
title.Text = "🚚 DELIVERY MISSION"
title.TextScaled = true
title.Font = Enum.Font.GothamBold
title.TextColor3 = Color3.new(1, 1, 1)
------------------------------
-- Create the Player Count label
------------------------------
local playerCount = Instance.new("TextLabel")
playerCount.Name = "PlayerCount"
playerCount.Parent = frame
playerCount.Size = UDim2.new(1, 0, 0.25, 0)
playerCount.Position = UDim2.new(0, 0, 0.3, 0)
playerCount.BackgroundTransparency = 1
playerCount.Text = "0/4 Players"
playerCount.TextScaled = true
playerCount.Font = Enum.Font.SourceSans
playerCount.TextColor3 = Color3.fromRGB(200, 200, 200)
------------------------------
-- Create the Status label (for countdown or messages)
------------------------------
local status = Instance.new("TextLabel")
status.Name = "Status"
status.Parent = frame
status.Size = UDim2.new(1, 0, 0.25, 0)
status.Position = UDim2.new(0, 0, 0.55, 0)
status.BackgroundTransparency = 1
status.Text = "Waiting for players..."
status.TextScaled = true
status.Font = Enum.Font.SourceSans
status.TextColor3 = Color3.fromRGB(255, 255, 100)
------------------------------
-- Create the Leave Queue button
------------------------------
local leaveButton = Instance.new("TextButton")
leaveButton.Name = "LeaveButton"
leaveButton.Parent = frame
leaveButton.Size = UDim2.new(0.8, 0, 0.2, 0)
leaveButton.Position = UDim2.new(0.1, 0, 0.8, 0)
leaveButton.BackgroundColor3 = Color3.fromRGB(200, 50, 50)
leaveButton.Text = "LEAVE QUEUE"
leaveButton.TextScaled = true
leaveButton.Font = Enum.Font.SourceSansBold
leaveButton.TextColor3 = Color3.new(1, 1, 1)
leaveButton.Visible = false -- Hide by default; will be shown when the player is in the queue
------------------------------
-- Event Handling: Listen for server GUI updates
------------------------------
-- Wait for our RemoteEvents in ReplicatedStorage.
local updateGUI = ReplicatedStorage:WaitForChild("UpdateLobbyGUI")
local leaveQueue = ReplicatedStorage:WaitForChild("LeaveQueue")
updateGUI.OnClientEvent:Connect(function(playerCountText, statusText, queuedPlayers)
-- Update the player count & status text
playerCount.Text = playerCountText
status.Text = statusText
-- Show the leave button only if the player is in the queue.
local isInQueue = false
for _, p in ipairs(queuedPlayers) do
if p == player then
isInQueue = true
break
end
end
leaveButton.Visible = isInQueue
end)
------------------------------
-- Leave Button: When the player clicks, signal the server.
------------------------------
leaveButton.MouseButton1Click:Connect(function()
leaveQueue:FireServer()
end)
What This Script Does:
Automatically Creates the UI:
It builds a ScreenGui and a BillboardGui with a frame, title, player count indicator, status text, and a leave queue button.
Attaches to a “GUIAnchor” Part:
It waits for a part called GUIAnchor in the Workspace and uses it as the adornee. (Make sure you have that part in your scene.)
Listens for UI Update Events:
It listens for RemoteEvents (which you’ll see in the accompanying lobby script) to update the texts (e.g., showing the countdown or “TELEPORTING…” when the countdown reaches 0).
Handles the Leave Button Click:
When you click “LEAVE QUEUE,” it fires a RemoteEvent to let the server know you’re leaving.
Next Steps:
Make sure you have the RemoteEvents named UpdateLobbyGUI and LeaveQueue in ReplicatedStorage (as created in the server script from the previous instructions).
Test your game in Roblox Studio. When players step into the lobby (the designated “force zone”), they’ll be anchored to the teleport pad, and the GUI above the “GUIAnchor” will update with the countdown, player count, and status.
You can further tweak colors, sizes, or positions as needed using the properties in the code.
This automated UI creation should help you get started without having to manually create each element in Roblox Studio’s UI editor. Let me know if you need more help or further customization!