so i have a server system which shows all servers in a gui and when you click join on the server it should teleport you to that specific server,
there is a lobby game (where these scripts take place) and the Main game (where player should be teleported to)
however i am confused on how i could change my code to do that, i know to utilize JobId but i dont see where to use it
there is a server script which handles the data, a folder of the servers in repstorage, a local script which handles teleporting and gui
right now what the code does is teleport to a server in the LobbyGame, when it should teleported to a server in the MainGame
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
serverValue.Value = data.serverId .. " " .. data.players
serverValue.Parent = serversFolder
task.wait(5)
serverValue:Destroy()
--end
end)
while true do
local data = {
serverId = game.JobId,
players = #game.Players:GetPlayers()
}
ms:PublishAsync("ServerList", data)
task.wait(5)
end
local script:
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.ServerTemplate:Clone()
serverFrame:WaitForChild("ServerName").Text = name .. "\n ID: " .. id
serverFrame:WaitForChild("Players").Text = plrs .. "/" .. game.Players.MaxPlayers
table.insert(serverFrames, serverFrame)
-- If so, find out where they are
serverFrame.JoinButton.MouseButton1Click:Connect(function()
print(game.PlaceId)
print(id)
game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, id) --11363146366(this is the id to the game they should be tp too)
end)
script.Parent.List:ClearAllChildren()
script.UIListLayout:Clone().Parent = script.Parent.List
for i, serverFrame in pairs(serverFrames) do
serverFrame.Parent = script.Parent.List
end
end
end
updateGui()
game.ReplicatedStorage.Servers.ChildAdded:Connect(updateGui)
game.ReplicatedStorage.Servers.ChildRemoved:Connect(updateGui)