Hey everyone. For my upcoming game Im trying to get a server selector working I have 2 scripts but whatever I do nothing works. Any ideas on how I would fix this?
Server Script
local serversFolder = game.ReplicatedStorage:WaitForChild("Servers")
local ms = game:GetService("MessagingService")
ms:SubscribeAsync("ServerList", function(data)
data = data.Data
if data.serverId ~= game.JobId then
local serverValue = script.ServerName:Clone()
serverValue.Name = "Server" .. #serversFolder:GetChildren() + 1
print("server made")
serverValue.Value = data.serverId .. " " .. data.players
serverValue.Parent = serversFolder
task.wait(5)
serverValue:Destroy()
end
end)
while game.PrivateServerId == "" do
local data = {
serverId = game.JobId,
players = #game.Players:GetPlayers()
}
ms:PublishAsync("ServerList", data)
task.wait(5)
end
Client Script for the ui.
local function updateGui()
local serverFrames = {}
for i, serverValue in pairs(game.ReplicatedStorage.Servers:GetChildren()) do
local name = serverValue.Name
local serverStats = string.split(serverValue.Value, " ")
local id = serverStats[1]
local plrs = serverStats[2]
local serverFrame = script.ServerFrame:Clone()
serverFrame.Info:WaitForChild("Title").Text = name .. "\n # " .. id
serverFrame.Avatars:WaitForChild("PlayerCount").Text = plrs .. "/" .. game.Players.MaxPlayers
table.insert(serverFrames, serverFrame)
serverFrame.Join.MouseButton1Click:Connect(function()
game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, id)
end)
script.Parent.List:ClearAllChildren()
for i, serverFrame in pairs(serverFrames) do
serverFrame.Parent = script.Parent.Parent.List
script.Parent.NoServers.Visible = false
end
end
end
updateGui()
game.ReplicatedStorage.Servers.ChildAdded:Connect(updateGui)
game.ReplicatedStorage.Servers.ChildRemoved:Connect(updateGui)