So basically I want to make a gui that displays a multitude of servers running on a game/place so you can join that server with a click of a button; I also want it to show information about the server such as player count, etc. I don’t know how to go about making this so I’m posting here in hopes of help.
Any contributions are appreciated.
2 Likes
This might help
3 Likes
local http = game:GetService("HttpService")
local getAsync = http.GetAsync
local jsonDecode = http.JSONDecode
local serversUrl = "https://games.roproxy.com/v1/games/%s/servers/%s?limit=100&cursor=%s"
local function getServersRecursive(placeId, serverType, cursor, servers, tries)
placeId = placeId or game.PlaceId
serverType = serverType or "Public"
cursor = cursor or ""
servers = servers or {}
tries = tries or 5
if tries == 0 then return {} end
local requestUrl = serversUrl:format(placeId, serverType, cursor)
local success, result = pcall(getAsync, http, requestUrl)
if success then
if result then
local success2, result2 = pcall(jsonDecode, http, result)
if success2 then
if result2 then
for _, server in ipairs(result2.data) do
servers[server.id] = {
["maxPlayers"] = server.maxPlayers,
["totalPlayers"] = server.playing,
["fps"] = server.fps,
["ping"] = server.ping
}
end
cursor = result2.nextPageCursor
if cursor then
return getServersRecursive(placeId, serverType, cursor, servers, tries)
else
return servers
end
end
else
task.wait()
warn(result2)
tries -= 1
return getServersRecursive(placeId, serverType, cursor, servers, tries)
end
end
else
task.wait()
warn(result)
tries -= 1
return getServersRecursive(placeId, serverType, cursor, servers, tries)
end
end
local servers = getServersRecursive(1818)
for serverId, serverInfo in pairs(servers) do
print("ID: "..serverId)
print("Players: "..serverInfo.totalPlayers.."/"..serverInfo.maxPlayers)
print("FPS: "..serverInfo.fps)
print("Ping: "..serverInfo.ping)
print("")
end
The following API endpoint was used:
https://games.roblox.com/docs#!/GameInstances/get_v1_games_placeId_servers_serverType
Feel free to change, “1818” to a different place ID.
Output:
1 Like
Wow! Thank you so much, this really helped me out.
1 Like
While trying to do basically the same the OP, I’ve found this thread & your code. Upon giving it a shot, I’m turning over 403 Forbidden errors. Any ideas would could be causing that to turn out?
4 Likes
im having the same problem, kinda new to scripting and have no idea how half of this works. been browsing on more forums and i think its due to roproxy shutting down? then again i have no idea and im looking for a way to fix this