Hi!
I am making a server list system and I need help with the creation of private servers. The private servers should be displaying on the server list and you should be able to join them but it still says the place is restricted even though the access code is the correct one.
In the client script this gets repeatedly displayed:
Server Script:
local ServersFolder = game:GetService("ReplicatedStorage"):WaitForChild("Servers")
local MessagingService = game:GetService("MessagingService")
local TPS = game:GetService("TeleportService")
MessagingService:SubscribeAsync("ServerList", function(data)
data = data.Data
if data.serverId ~= game.JobId then
local serverValue = script:WaitForChild("ServerName"):Clone()
serverValue.Value = data.serverId .. " " .. data.players
serverValue.Parent = ServersFolder
task.wait(5)
serverValue:Destroy()
end
end)
game:GetService("ReplicatedStorage"):WaitForChild("CreateServer").OnServerEvent:Connect(function(player)
local AccessCode = TPS:ReserveServer(13628003081)
TPS:TeleportToPrivateServer(13628003081, AccessCode, {player})
end)
while true do
if game.PrivateServerId == "" then
local data = {
serverId = game.JobId,
players = #game:GetService("Players"):GetPlayers()
}
MessagingService:PublishAsync("ServerList", data)
else
local data = {
serverId = game.PrivateServerId,
players = #game:GetService("Players"):GetPlayers()
}
MessagingService:PublishAsync("ServerList", data)
end
task.wait(5)
end
Client Script:
local function UpdateGui()
local ServerFrames = {}
for i, v in pairs(game:GetService("ReplicatedStorage"):WaitForChild("Servers"):GetChildren()) do
local name = v.Name
local ServerStats = string.split(v.Value, " ")
local ID = ServerStats[1]
local Players = ServerStats[2]
print(ID)
local ServerFrame = script:WaitForChild("Template"):Clone()
ServerFrame:WaitForChild("ServerName").Text = name .. "/".. game:GetService("Players").MaxPlayers
ServerFrame:WaitForChild("Players").Text = Players.."/"..game:GetService("Players").MaxPlayers
table.insert(ServerFrames, ServerFrame)
ServerFrame:WaitForChild("JoinButton").MouseButton1Click:Connect(function()
local success, errorMessage = pcall(function()
game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, ID, game:GetService("Players").LocalPlayer)
end)
if not success then
game:GetService("TeleportService"):TeleportToPrivateServer(game.PlaceId, ID, {game:GetService("Players").LocalPlayer})
end
end)
script.Parent:WaitForChild("ScrollingFrame"):ClearAllChildren()
script.UIListLayout:Clone().Parent = script.Parent:WaitForChild("ScrollingFrame")
for i, v in pairs(ServerFrames) do
v.Parent = script.Parent:WaitForChild("ScrollingFrame")
end
end
end
UpdateGui()
game:GetService("ReplicatedStorage"):WaitForChild("Servers").ChildAdded:Connect(UpdateGui)
game:GetService("ReplicatedStorage"):WaitForChild("Servers").ChildRemoved:Connect(UpdateGui)
script.Parent:WaitForChild("Create").MouseButton1Click:Connect(function()
game:GetService("ReplicatedStorage").CreateServer:FireServer()
end)