Goal
I am trying to create a server list inside my Lobby place to display servers for the Multiplayer place. I also want to make sure there is a button for players to go to a new, empty server whenever there are none currently open. My scripts right now do not have that functionality.
Issue
I have tried looking for tutorials/help through YouTube and other forums, but I can only find server lists for the place that the list is displayed in.
My setup
My current setup is from HowToRoblox on YT with some tweaks. I have a Servers folder in RS, a ServersHandler with a string value ServerName in SSS, and a LocalServersHandler inside my MultiplayerFrame with the ServerButtonTemplate, NoServersButton, and a UIListLayout. Inside the MultiplayerFrame is a ServersFrame holding the List scrolling frame.
I like the way that this set up works, but I need it to be servers for the Multiplayer place instead of the lobby.
Here are my current scripts:
ServersHandler (SSS)
local replicatedStorage = game:GetService("ReplicatedStorage")
local serversFolder = replicatedStorage:WaitForChild("Servers")
local ms = game:GetService("MessagingService")
local serverId = game.JobId
local serverNamePrefix = "Server_"
-- Subscribe to updates for other servers
ms:SubscribeAsync("ServerList", function(data)
data = data.Data
-- Only add or update entries for other servers
if data.serverId ~= serverId then
-- Find or create a server entry
local existingServer = serversFolder:FindFirstChild(data.serverId)
if not existingServer then
existingServer = Instance.new("StringValue")
existingServer.Name = data.serverId -- Use server ID as the unique name
existingServer.Parent = serversFolder
end
-- Set the value in "serverId,players,maxPlayers" format
existingServer.Value = data.serverId .. "," .. data.players .. "," .. data.maxPlayers
-- Remove stale server data after a timeout
wait(10)
if existingServer.Parent == serversFolder then
existingServer:Destroy()
end
end
end)
-- Publish server data periodically
while game.VIPServerId == "" do
local data = {
serverId = serverId,
players = #game.Players:GetPlayers(),
maxPlayers = game.Players.MaxPlayers
}
-- Publish current server data
ms:PublishAsync("ServerList", data)
wait(5)
end
LocalServersHandler (MultiplayerFrame)
local replicatedStorage = game:GetService("ReplicatedStorage")
local teleportService = game:GetService("TeleportService")
local serversFolder = replicatedStorage:WaitForChild("Servers")
local serversFrame = script.Parent.ServersFrame.List
local serverButtonTemplate = script.ServerButtonTemplate
local uiListLayout = serversFrame:FindFirstChildOfClass("UIListLayout") or Instance.new("UIListLayout", serversFrame)
-- Add debounce to avoid overlapping refreshes
local isUpdating = false
-- Function to update the server list UI
local function updateGui()
if isUpdating then return end
isUpdating = true
serversFrame:ClearAllChildren() -- Clear previous server buttons
-- Loop through each server entry
for _, serverValue in pairs(serversFolder:GetChildren()) do
local serverStats = string.split(serverValue.Value, ",") -- Use comma separator
local id = serverStats[1]
local plrs = serverStats[2]
local maxPlrs = serverStats[3]
-- Clone and set up a server button
local serverButton = serverButtonTemplate:Clone()
serverButton.ServerName.Text = "Server: " .. serverValue.Name
serverButton.ServerPlayers.Text = "Players: " .. plrs .. "/" .. maxPlrs
-- Set up teleport on button click
serverButton.MouseButton1Click:Connect(function()
teleportService:TeleportToPlaceInstance(game.PlaceId, id)
end)
serverButton.Parent = serversFrame -- Add button to UI
serverButton.Visible = true
end
isUpdating = false
end
-- Initial GUI update
updateGui()
-- Update the server list whenever a server entry is added or removed
serversFolder.ChildAdded:Connect(updateGui)
serversFolder.ChildRemoved:Connect(updateGui)
-- Trigger update when the Multiplayer menu is opened
script.Parent.Parent.MenuFrame.MultiplayerButton.MouseButton1Click:Connect(updateGui)
I know this is annoying to some, but I am not too good with scripting, but I do understand the basics.
Also, this is my first time uploading on here, so I apologize if this is hard to understand. Help will be very greatly appreciated.