How do I get a list of all of the servers of a place within my game?

Current Code:

function getServerList(placeId)
	local cursor
	local servers = {}
	repeat
		local response = HttpService:JSONDecode(HttpService:GetAsync("https://games.roblox.com/v1/games/"..placeId.."/servers/Public?sortOrder=Asc&limit=10" .. (cursor and "&cursor=" .. cursor or "")))
		for _, v in pairs(response.data) do
			table.insert(servers, v)
		end
		cursor = response.nextPageCursor
	until not cursor
	return servers
end

The result I want to get:
https://games.roblox.com/docs#!/Games/get_v1_games_placeId_servers_serverType

Error:
“https://games.roblox.com/v1/games/7784928804/servers/Public?sortOrder=Asc&limit=10: Trust check failed”

More Info:
From what I’ve seen people say its that I can’t directly get the data from roblox. How should I go about doing this? All this is a bit confusing for me too so if anyone can explain a bit more how this stuff works I’d appreciate it. I’ve never used anything with http before and even had that disabled on studio until now.

4 Likes

You could do this with DataStore. Basically create a DataStore and every time a new server starts call :UpdateAsync() and save that server ID to the DataStore, and when the server ends just delete it from the DataStore. Then :GetAsync() on the server to recieve the list of servers. I’m not familiar with HTTP :GetAsync() or :PostAsync() but I don’t think you can recieve the list of servers through that.

4 Likes

I think it would be more efficient to use the Messaging Service inestead of Http Requests, it would be something like this:
By the way this only works in your game, but maybe it can help.

local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")
local MessagingService = game:GetService("MessagingService")

MessagingService:SubscribeAsync("Servers",function(Message)
	--Stuff Here
end)

while true do
	local Data = {
		game.JobId -- This will return the job id from the current server of your game
	}
	local Encoded = HttpService:JSONEncode(Data)
	local Sucess,Error = pcall(function()
		MessagingService:PublishAsync("Servers",Encoded)
	end)
	task.wait(5)
end

I suggest you check the documentation of MessagingService | Roblox Creator Documentation.

11 Likes

Try

local HttpService = game:GetService("HttpService")
function getServerList(placeId)
	local cursor
	local servers = {}
	repeat
		local response = HttpService:JSONDecode(HttpService:GetAsync("https://games.rprxy.xyz/v1/games/"..placeId.."/servers/Public?sortOrder=Asc&limit=10" .. (cursor and "&cursor=" .. cursor or "")))
		for _, v in pairs(response.data) do
			table.insert(servers, v)
		end
		cursor = response.nextPageCursor
	until not cursor
	return servers
end
1 Like

To elaborate on what @AC_Starmarine did, Roblox blocks HttpService requests to roblox.com. That’s what gives you the “trust check failed” message. This can actually be avoided by using a proxy. See here: HttpService “Trust Check Failed” Error - Help and Feedback / Scripting Support - DevForum | Roblox

3 Likes

@Sougood This option seems like it can work and I might give it a try if message service fails me.

@Zadkay Yeah I ended up trying that and the info sending is pretty quick and effective!

@AC_Starmarine I’ve tried using rprxy.xyz too but it is no longer available. An alternative is if I setup my own http thing which I’m still a bit clueless about.

1 Like

You can use roproxy as an alternative! RoProxy.com - A free, rotating proxy for Roblox APIs - Resources / Community Resources - DevForum | Roblox

2 Likes

How would I achieve this if I have a universe and I want it to gather places under another place

2 Likes

wortahel is that no server list

Did this ever work? Because I’m looking into doing the same thing as well.

why do you need to json encode the game.jobid before you send it via publish async