Using the official Roblox Api, you can get the number of players in several different places.
For example, if I wanted to check how many people were playing crossroads (place id 1818), I would go to the link https://www.roblox.com/games/getgameinstancesjson?placeId=1818&startindex=0. The text it shows is:
{
"PlaceId":1818,
"ShowShutdownAllButton":false,
"Collection":[
{
"Capacity":8,
"Ping":66,
"Fps":59.974594,
"ShowSlowGameMessage":false,
"Guid":"8ad4c4b2-5c00-41f7-92f9-747b60382baa",
"PlaceId":1818,
"CurrentPlayers":[
{
"Id":0,
"Username":"A Roblox Player",
"Thumbnail":{
"AssetId":0,
"AssetHash":null,
"AssetTypeId":0,
"Url":"https://tr.rbxcdn.com/0f0a14eb846140dfc1f28870921b38d8/48/48/AvatarHeadshot/Png",
"IsFinal":true
}
},
...
],
"UserCanJoin":true,
"ShowShutdownButton":false,
"JoinScript":"Roblox.GameLauncher.joinGameInstance(1818, \"8ad4c4b2-5c00-41f7-92f9-747b60382baa\")",
"FriendsDescription":"",
"FriendsMouseover":"",
"PlayersCapacity":"7 of 8 players max"
},
...
],
"TotalCollectionSize":3
}
To go to the link with Roblox scripts, you can use
local HttpService = game:GetService("HttpService")
local PlaceId = 1818
local StartIndex = 0
local Link = string.format("https://www.rprxy.xyz/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, StartIndex)
local Data = HttpService:GetAsync(Link)
print(Data)
It will print the data in the output. But let's say that you want to turn it into a Lua table. You would, of course, use HttpService:JSONDecode. Let's add that to our script.
local HttpService = game:GetService("HttpService")
local PlaceId = 1818
local StartIndex = 0
local Link = string.format("https://www.roblox.com/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, StartIndex)
local Data = HttpService:GetAsync(Link)
local DecodedData = HttpService:JSONDecode(Data)
Count the number of people in the servers
local HttpService = game:GetService("HttpService")
local PlaceId = 1818
local StartIndex = 0
local Link = string.format("https://www.roblox.com/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, StartIndex)
local Data = HttpService:GetAsync(Link)
local DecodedData = HttpService:JSONDecode(Data)
local PlayerCount = 0
for Index, Server in pairs(DecodedData["Collection"]) do
PlayerCount += #Server["CurrentPlayers"]
end
Notice this only returns the first ten servers. This problem can be easily solved by integrating a loop.
local HttpService = game:GetService("HttpService")
local PlaceId = 1818
local StartIndex = 0
local Link = string.format("https://www.roblox.com/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, StartIndex)
local Data = HttpService:GetAsync(Link)
local DecodedData = HttpService:JSONDecode(Data)
for Index, Server in pairs(DecodedData["Collection"]) do
PlayerCount += #Server["CurrentPlayers"]
end
for NewStartIndex = 10, DecodedData["TotalCollectionSize"], 10 do
Link = string.format("https://www.roblox.com/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, NewStartIndex)
local NewData = HttpService:GetAsync(Link)
local NewDecodedData = HttpService:JSONDecode(NewData)
for Index, Server in pairs(NewDecodedData["Collection"]) do
PlayerCount += #Server["CurrentPlayers"]
end
end
print(PlayerCount)
Hope this works!
*[Lua]: The programming language used in Roblox
2 comments
If you cant understand what i mean, Sorry. It's a bit hard to explain.
Title change: Get number of players in Roblox place