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
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)
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)
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)
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)
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)
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)
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.
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