You’ll want to use the Games Web API in order to get the number of players playing in a game.
You’ll just need to use HttpService to send a request, and then the api endpoint used will return the number of players currently playing the game. (Note: HttpService doesn’t allow direct Http requests to the Roblox Web API, so you’ll need to use a proxy )
local HttpService = game:GetService("HttpService")
local function getConcurrentPlayers(universeId: number)
local data
local success, errorMessage = pcall(function() -- Always use a pcall when sending http requests
data = HttpService:GetAsync(`https://games.roblox.com/v1/games?universeIds={universeId}`) -- Remember to replace the endpoint with a proxy equivalent, or else it wont work
end)
if success then
local gameData = HttpService:JSONDecode(data)
local playerCount: number = gameData[0].playing
return playerCount
else
warn(`Error when attempting to get Game Data: {errorMessage}`)
end
In the snippet above, we send a Http GET Request to this endpoint:
https://games.roblox.com/v1/games
to get the game data of the provided universeId query.
When a valid Universe ID is provided, the endpoint will return this json response:
Expand
{
"data": [
{
"id": 0,
"rootPlaceId": 0,
"name": "string",
"description": "string",
"sourceName": "string",
"sourceDescription": "string",
"creator": {
"id": 0,
"name": "string",
"type": "string",
"isRNVAccount": true,
"hasVerifiedBadge": true
},
"price": 0,
"allowedGearGenres": [
"string"
],
"allowedGearCategories": [
"string"
],
"isGenreEnforced": true,
"copyingAllowed": true,
"playing": 0,
"visits": 0,
"maxPlayers": 0,
"created": "2024-04-30T16:30:49.188Z",
"updated": "2024-04-30T16:30:49.188Z",
"studioAccessToApisAllowed": true,
"createVipServersAllowed": true,
"universeAvatarType": 1,
"genre": "string",
"isAllGenre": true,
"isFavoritedByUser": true,
"favoritedCount": 0
}
]
}
We’d then get the playing
property inside the json response, in which the value of the playing
property is the amount of players currently playing the game.
I hope this helped