There are posts but none of them address the problem I’m facing. Everything works fine except for the fact that if you create a new server it only updates the server list with the people in the server that you were in and the servers don’t save on leave. The system allows you to create a reserved server with a custom name and description and a voice chat option. It works by sending the information to the server and putting the server data (ServerID, Name, Description, etc.) into a StringValue and then putting it inside of a Folder which the GUI handler adds all the buttons and text.
ServersHandler:
local serversFolder = game.ReplicatedStorage:WaitForChild("Servers")
local Messenger = require(game.ReplicatedStorage:WaitForChild("Messenger"))
local events = game.ReplicatedStorage:WaitForChild("Events")
local rate = 1
local ms = Messenger.new("ServerList")
local serverData = {
ServerName = nil,
Description = nil,
VCOn = nil,
ID = nil
}
events.ToServer.Event:Connect(function(c, n, d, vc)
serverData.ID = c
serverData.ServerName = n
serverData.Description = d
serverData.VCOn = (vc == "ON")
end)
ms:SubscribeAsync(function(message)
local data = message
game.ReplicatedStorage:WaitForChild("Servers"):ClearAllChildren()
if serverData.ServerName ~= nil and serverData.Description ~= nil and serverData.VCOn ~= nil then
local serverValue = script.ServerName:Clone()
serverValue.Name = "Server" .. #serversFolder:GetChildren() + 1
serverValue.Parent = serversFolder
serverValue.Value = (data.serverId or "[UnknownID]") .. " " .. (data.players or "0") .. " " .. (serverData.ServerName or "[N/A]") .. " " .. (serverData.Description or "[No Description]") .. " " .. tostring(serverData.VCOn)
print(unpack(game.Players:GetPlayers()))
if data.players == 0 then
serverValue:Destroy()
end
end
end)
while true do
local success, err = pcall(function()
ms:PublishAsync({
serverId = serverData.ID,
serverName = serverData.ServerName,
description = serverData.Description,
players = #game.Players:GetPlayers(), -- this line is the one that needs to get the player in the reserved server, not this one.
vcOn = serverData.VCOn or false
})
end)
if not success then
warn("failed to publish server data: " .. tostring(err))
end
task.wait(rate)
end
CreateHandler:
local TeleportService = game:GetService("TeleportService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Events = ReplicatedStorage:WaitForChild("Events")
local CreateServer = Events:WaitForChild("CreateServer")
local PLACE_ID = game.PlaceId
local reservedServers = {}
CreateServer.OnServerEvent:Connect(function(player, Desc, Name, VCMode)
local success, code = pcall(function()
return TeleportService:ReserveServer(PLACE_ID)
end)
if success then
reservedServers[code] = {
Description = Desc,
ServerName = Name,
VCMode = VCMode,
}
game.ReplicatedStorage:WaitForChild("Events").ToServer:Fire(code, Name, Desc, VCMode)
TeleportService:TeleportToPrivateServer(PLACE_ID, code, {player}, nil, {Description = Desc, ServerName = Name, VCMode = VCMode})
else
warn("Failed to reserve server; code: " .. tostring(code))
end
end)
Below is the basic logic of what it does. (Doesn’t use attributes, uses the StringValues value instead. Sorry for bad formatting, i’m new to devforum.)