How do i make custom server lobby (joinning and creating)

so i tryed to see some tutorials and yet no information, what im trying to gain is that so players could create servers (private servers) while the other players could be able to join it, only problem is that i cant figure out how to use the new fuction (MessagingService), if you would mind, can you explain it to me

also heres some scripts i was trying to make (before i gave up)

local script

local rep = game.ReplicatedStorage
local serverstorage = rep.SeverFolder

local function updateserver()
	for i, ServerName in pairs(serverstorage:GetChildren()) do
		local serverStats = string.split(ServerName.Value, "")
		local plr = serverStats[2]
		local ServerName = serverStats[1]
		local ServerId = serverStats[3]
		
		local ServerFrame = script.CloneServerFrame:Clone()
		ServerFrame.Parent = script.Parent.CustomServerFrame.ScrollingFrame
		ServerFrame.ServerName.Text = ServerName
		ServerFrame.PlayerCount.Text = plr.."/20"
	end
end
1 Like

changed the local script abit

local rep = game.ReplicatedStorage
local serverstorage = rep.SeverFolder
local frames = {}

local function updateserver()
	for i, ServerName in pairs(serverstorage:GetChildren()) do
		local serverStats = string.split(ServerName.Value, "")
		local plr = serverStats[2]
		local ServerName = serverStats[1]
		local ServerId = serverStats[3]
		
		local ServerFrame = script.CloneServerFrame:Clone()
		ServerFrame.ServerName.Text = ServerName
		ServerFrame.PlayerCount.Text = plr.."/20"
		
		table.insert(frames, ServerFrame)
		
		ServerFrame.TextButton.MouseButton1Down:Connect(function()
			game:GetService("TeleportService"):Teleport(ServerId, game.Players.LocalPlayer)
		end)
		
		script.Parent.CustomServerFrame.ScrollingFrame:ClearAllChildren()
		
		script.UIGridLayout:Clone().Parent = script.Parent.CustomServerFrame.ScrollingFrame
		
		for i, frames in pairs(ServerFrame) do
			ServerFrame.Parent = script.Parent.CustomServerFrame.ScrollingFrame
		end
	end
end

updateserver()

rep.SeverFolder.ChildAdded:Connect(updateserver)
rep.SeverFolder.ChildRemoved:Connect(updateserver)

Part where im stuck at, (trying to figure out how to make the game detect for place ids)

local message = game:GetService("MessagingService")

message:PublishAsync("ServerList", function(data)
	data = data.Data
	
	if data == game.PlaceId then
		
	end
end)


1 Like

I have updated the script a bit but i dont know how to make, nvm

local message = game:GetService("MessagingService")
local specificPlaceId = 76645132977147

message:PublishAsync("ServerList", function(data, name)

	if data.Data == specificPlaceId then
		local value = script.ServerName:Clone()
		value.Name = name
		value.Value = data.serverid.. "" ..data.players
		value.Parent = game.ReplicatedStorage.SeverFolder
		
		wait(0.5)
		value:Destroy()
	end
end)

heres the scripts i need help with

Creating the server (Local Script)

local textbox = script.Parent.Parent.TextBox
local teleportserver = game:GetService("TeleportService")
local servername = ""
local reservedid = teleportserver:ReserveServer(76645132977147)

textbox.FocusLost:Connect(function(enter)
	textbox.Text = servername
end)

script.Parent.MouseButton1Down:Connect(function()
	game.ReplicatedStorage.FireServerName:FireServer(servername, reservedid)
	teleportserver:Teleport(reservedid, game.Players.LocalPlayer)
end)

ServerHandler (ServerScript)

local message = game:GetService("MessagingService")
local specificPlaceId = 76645132977147 -- Replace with your specific Place ID

local function onMessageReceived(data)
	if data.Data == specificPlaceId then
		local value = script.ServerName:Clone()
		value.Name = data.Name
		value.Value = data.serverid .. "" .. data.players
		value.Parent = game.ReplicatedStorage.SeverFolder

		wait(0.5)
		value:Destroy()
	end
end

local success, err = pcall(function()
	message:SubscribeAsync("ServerList", onMessageReceived)
end)

if not success then
	warn("Failed to subscribe to ServerList: " .. err)
end

and server updater (Local Script)

local rep = game.ReplicatedStorage
local serverstorage = rep.SeverFolder
local frames = {}

local function updateserver()
	for i, ServerName in pairs(serverstorage:GetChildren()) do
		local serverStats = string.split(ServerName.Value, "")
		local plr = serverStats[2]
		local ServerId = serverStats[3]
		
		local ServerFrame = script.CloneServerFrame:Clone()
		ServerFrame.ServerName.Text = ServerName.Name
		ServerFrame.PlayerCount.Text = plr.."/20"
		
		table.insert(frames, ServerFrame)
		
		ServerFrame.TextButton.MouseButton1Down:Connect(function()
			game:GetService("TeleportService"):Teleport(ServerId, game.Players.LocalPlayer)
		end)
		
		script.Parent.CustomServerFrame.ScrollingFrame:ClearAllChildren()
		
		script.UIGridLayout:Clone().Parent = script.Parent.CustomServerFrame.ScrollingFrame
		
		for i, frames in pairs(ServerFrame) do
			ServerFrame.Parent = script.Parent.CustomServerFrame.ScrollingFrame
		end
	end
end

updateserver()

rep.SeverFolder.ChildAdded:Connect(updateserver)
rep.SeverFolder.ChildRemoved:Connect(updateserver)

boosting because im still stuck on this

1 Like

i need help pleaseeeee I NEED ITAAAA

1 Like

Bro i really need help, IM being serious

TeleportService:ReserveServer() and TeleportService:Teleport() (you should really be using TeleportService:TeleportAsync()) is not callable on the client.

You should use remote events from the client to call the server, where you should create the server and then store/send it to other servers.

1 Like

Thanks for responding, i couldnt be more grateful but what im struggling tho is how to create multiple vip servers of a place id (Not the main universal place)

including how to call on each vip server to get the player count

Is this Okay?

local DataStorage = game:GetService("DataStoreService")
local ServerCodeStorage = DataStorage:GetDataStore("ServerData")
local tp = game:GetService("TeleportService")
local rep = game.ReplicatedStorage

rep.RemoteEvents.FireCreateServer.OnServerEvent:Connect(function(plr, ServerName)
	local code = tp:ReserveServer(76645132977147)
	local tpOp = Instance.new("TeleportOptions")
	local success, err = pcall(function()
		ServerCodeStorage:SetAsync(ServerName, code)
	end)
	if success then
		print("Created Server")
		tp:TeleportAsync(code, {plr}, tpOp)
		local value = Instance.new("StringValue",game.ReplicatedStorage.SeverFolder)
		value.Name = ServerName
		value.Value = code..""..tpOp
	else
		print("Error Creating Server")
	end
end)

It looks like if someone were to trace your remote, they’d be able to teleport anyone they want.

1 Like

i dont get it, can you explain plsss

made another script that clones a frame

local rep = game.ReplicatedStorage
local serverFolder = rep.SeverFolder

local function updata()
	for _, Value in pairs(serverFolder:GetChildren()) do
		if Value:IsA("StringValue") then
			local valueSplit = string.split(Value.Value)
			local Id = valueSplit[1]
			local players = valueSplit[2]
			local code = valueSplit[3]
			local name = Value.Name
			local gui = script.ServerName:Clone()
			gui.ServerName.Text = name
			gui.Name = name
			gui.PlayerCount.Text = players.. "/20"
			script.Parent.CustomServerFrame.ScrollingFrame:ClearAllChildren()
			local ui = script.UIListLayout:Clone()
			ui.Parent = workspace
			gui.Parent = script.Parent.CustomServerFrame.ScrollingFrame
		end
	end
end

updata()
serverFolder.ChildAdded:Connect(updata)
serverFolder.ChildRemoved:Connect(updata)

I’ve actually just finished a lobby system, so I can send some of the scripts I made.

This is a script in ServerScriptService that manages player created lobbies that I made.
Don’t copy it entirely, only take notes on what it does and replicate it’s function in your own script.

-- Manage player lobbies
local lobbies = game.ReplicatedStorage.Lobbies
local event = game.ReplicatedStorage.Remote.Lobby

local teleportService = game:GetService("TeleportService")

game:GetService("RunService").Heartbeat:Connect(function(deltaTime: number)
	
	-- Loop over and manage all lobbies
	for _, lobby: Folder in pairs(lobbies:GetChildren()) do
		if lobby:HasTag("Template") then continue end
		
		local players = lobby.Players:GetChildren()
		
		for _, player: ObjectValue in players do
			if not player.Value then
				player:Destroy()
			end
		end
		
		-- Get host and assign new host if old one left
		local host = lobby.Players:FindFirstChild(lobby.Host.Value)
		if not host then
			for _, player: ObjectValue in players do
				if player.Value and player.Name ~= lobby.Host.Value then
					lobby.Host.Value = player.Value.Name
					host = player.Value
					event:FireAllClients("updateLobbies")
					break
				end
			end
		end
		
		if not host then -- Host left and lobby is empty
			lobby:Destroy()
			event:FireAllClients("updateLobbies")
			continue
		end
	end
end)

local utils = {}
function utils.GetLobby(player: Player)
	for _, lobby: Folder in pairs(lobbies:GetChildren()) do
		if lobby:HasTag("Template") then continue end
		for _, plr: ObjectValue in pairs(lobby.Players:GetChildren()) do
			if plr.Name == player.Name then
				return lobby
			end
		end
	end
	return nil
end
function utils.LeaveCurrentLobby(player: Player)
	local lobby = utils.GetLobby(player)
	if not lobby then return end
	for _, plr: ObjectValue in pairs(lobby.Players:GetChildren()) do
		if plr.Value == player then
			plr:Destroy()
			
			event:FireAllClients("updateLobbies")
			event:FireClient(player, "openPage", "Lobbies")
			break
		end
	end
end
function utils.JoinLobby(player: Player, lobby: Folder)
	if not lobby then return end

	utils.LeaveCurrentLobby(player) -- Leave current lobby if in one

	-- Join new lobby
	local newPlayer = Instance.new("ObjectValue")
	newPlayer.Name = player.Name
	newPlayer.Parent = lobby.Players
	newPlayer.Value = player
	
	event:FireAllClients("updateLobbies")
	event:FireClient(player, "openPage", "Current")
end

event.OnServerEvent:Connect(function(player: Player, data: {any})
	if not data or not data.func then return end
	
	if data.func == "Create" then
		utils.LeaveCurrentLobby(player)
		if lobbies:FindFirstChild(player.Name .. "'s lobby") then return end -- Prevent duplicates
		
		-- Create new lobby
		local newLobby = lobbies.Template:Clone()
		newLobby.Name = player.Name .. "'s lobby"
		newLobby.Parent = lobbies
		newLobby.Host.Value = player.Name
		newLobby:RemoveTag("Template")
		
		-- Add host to players
		local newPlayer = Instance.new("ObjectValue")
		newPlayer.Name = player.Name
		newPlayer.Parent = newLobby.Players
		newPlayer.Value = player
		
		local lSettings = newLobby.Settings
		lSettings.MaxPlayers.Value = data.MaxPlayers or 15
		lSettings.GenerationSeed.Value = data.GenerationSeed or math.random(-1000000, 1000000)
		lSettings.StarCount.Value = data.StarCount or 25
		lSettings.ClusterSize.Value = data.ClusterSize or 2500
		lSettings.JoinMode.Value = 0
		
		event:FireAllClients("updateLobbies")
		event:FireClient(player, "openPage", "Current")
	elseif data.func == "Join" then
		if not data.lobby then return end
		utils.JoinLobby(player, data.lobby)
	elseif data.func == "Leave" then
		utils.LeaveCurrentLobby(player)
	elseif data.func == "Kick" then
		local lobby = utils.GetLobby(player)
		if not lobby then return end
		if lobby.Host.Value ~= player.Name then return end
		
		local playerToKick = lobby.Players:FindFirstChild(data.PlayerToKick)
		if playerToKick then
			utils.LeaveCurrentLobby(game.Players:FindFirstChild(data.PlayerToKick))
		end
	elseif data.func == "Start" then
		local lobby = utils.GetLobby(player)
		if not lobby then return end
		if lobby.Host.Value ~= player.Name then return end
		
		local players = {}
		for _, plr: ObjectValue in pairs(lobby.Players:GetChildren()) do
			if plr.Value then
				table.insert(players, plr.Value)
				event:FireClient(plr.Value, "LoadGame")
			end
		end
		
		local generationSeed = lobby.Settings.GenerationSeed.Value
		local starCount = lobby.Settings.StarCount.Value
		local clusterSize = lobby.Settings.ClusterSize.Value
		
		local data = {
			generationSeed = generationSeed,
			starCount = starCount,
			clusterSize = clusterSize
		}
		
		print("Sending lobby '"..lobby.Name.."' to the cluster!")
		local server = teleportService:ReserveServer(94254084317259)
		
		teleportService:TeleportToPrivateServer(94254084317259, server, players, nil, data)
	end
end)
1 Like

oh… uhh my one is kinda like that but instead the players dont start when the host starts, instead the host can create a server (Basicly already create the server) and the players can join the server.

day 4 of asking how to fix the custom server thingy

day 6, i have searched every where yet still im stuck on creating a custom server which allows players to join and create

I haven’t made one myself but you should reverse a server, then im pretty sure you can use memorystore service to allow the servers to communicate with eachother, im planning to do something similar in my game so when i get around to doing it and if you still need help ill let you know

1 Like