Is there a way to show the amount of players in an another game?

Hello! I am in the progress of making a lobby, using which you can join some other games! However, I’ve ran into a problem; I want my players to know how many other players a specific game would have, to see if it’s worth joining. As far as my efforts have gone, I still haven’t found a solution.

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve the following; Player joins my game, which is a lobby for my other games. These are NOT places. They are full-out other games. I want to give my player an overview of how many players are in said game and if it’s worth joining.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that I don’t know how this would work. I can somewhat script, but I still haven’t found a way on how to do this. The main problem would be getting the actual player count from the other game, which I have no idea on how to do

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I asked on scriptinghelpers, however I haven’t been able to get an answer from there. I’ve also googled for similar questions, however to no avail. Since I use :Teleport() to get players from one game to another, I’ve also read up about it on the official Developer Hub and haven’t seemed to found anything.

Any help would be greatly appreciated! :]

3 Likes

Apart from some HttpsService wizardry that you’re probably not looking at getting into (unless you’re interested in like hosting a server and whatnot, along with having access to the other games in question), there is no simple way to do this at the moment. Universe level scripting and communication is in development over at Roblox HQ, but cross-Universe level stuff (what you’re describing) is not.

Ah, that’s a shame… Would something like this be coming in the future though?

Unfortunately from what we can tell based on information provided from Roblox (roadmap, announcements, etc.), nothing like that has been mentioned. So no, don’t count on it.

It is possible via HTT P. I am currently writing some api to get game statistics, Etc. Its nearl y finished and I will probably open source it after wards.

Yes, through the Games API. The endpoint you’re looking for will be /v1/games; if the docs page defaults to Games Api v2, just hit the drop down and go to Games Api v1. You will see all v1 endpoints there, so find /v1/games and click it for more information.

Do be aware, you will require a proxy to query any Roblox endpoints from HttpService. rprxy.xyz is the most popular one in use right now. You simply need to replace any cases of roblox.com with rprxy.xyz and the proxy will handle the API interaction and response returning for you.

The parameter is universeIds, so you can attach that via ?universeIds=. You can query a maximum of 100 games which are separated by commas, e.g. ?universeIds=1,2,3. Universe ids will be the game ids you want to see the players of. You can find this in many different fashions. For your own places, you would hit Configure this game and look in the URL bar for the game id, then plug it in here.

The response body is a JSON table with data about the places you’ve queried. The initial layer is a dictionary with the sole key of data and in there are arrays containing information about your queried places. To use this in a table format, pass the result through JSONDecode then access the data key. From here, you can access the playing key of the data table for your place which will determine how many players are active across your queried game.

As far as code samples go, I can supply you one. It’s broken down so you can see the steps. This example queries the current game and returns the players active within it.

local HttpService = game:GetService("HttpService")

local QUERY_URL = "https://games.rprxy.xyz/v1/games?universeIds="
local GAME_ID = game.GameId

-- "https://games.rprxy.xyz/v1/games?universeIds=000000"
local endpointResponse = HttpService:GetAsync(QUERY_URL .. GAME_ID)
local decodedResponse = HttpService:JSONDecode(endpointResponse)
local gameData = decodedResponse.data

local gameInformation = gameData[1]
local playersInGame = gameInformation.playing

print(playersInGame) -- 0

No wizardry, no self-hosting. Just using some nice endpoints. :slightly_smiling_face:

cc @ChiefWildin

14 Likes

Wonderful! Will be trying this out tomorrow. Thank you very much!

14:20:52.353 - ServerScriptService.Script:13: attempt to index nil with ‘playing’
14:20:52.354 - Stack Begin
14:20:52.354 - Script ‘ServerScriptService.Script’, Line 13
14:20:52.355 - Stack End

Showing me an error isn’t enough, you also have to show me what code you’re working with. If you’d like help on a problem, details are required. I ran that exact code sample in Studio since I wasn’t sure myself if that worked or not and did not encounter any such errors.

The GameId can be fetched by game.GameId if it’s your own game. If it’s another’s game, you will need to use the /v1/games/multiget-place-details endpoint and access the universeId field. The sole parameter is placeIds which takes a list of places to get place information from.

Wow I had no idea that existed. That’s pretty cool, great post.

2 Likes