Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you connect multiple game stats into a main lobby?

Asked by 4 years ago

Hey, so i was just wondering this to improve my stats of my game!

So ya'll know games like "tower battles" and "Tower Defense Simulator" right? if you do, then what i'm trying to figure out is how they connect the games of the teleport-er maps into the main lobby?

Lets say this as an example: A person plays a game in Tower Defense Simulator but there is no 1 in the lobby, and it shows 1 person is playing it. how do you connect that teleport-ed game to the lobby from the players?

I really need to understand this please, Thank you.

Links: Profile: https://web.roblox.com/users/202371881/profile Game: https://web.roblox.com/games/5149487599/NEW-GAMEMODE-TACTION Group: https://web.roblox.com/groups/6607132/BlueJ-Studios#!/about

0
If you cant understand what i mean, Sorry. It's a bit hard to explain. Bluejay20000 -11 — 4y
0
Title change: Get number of players in Roblox place User#30567 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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:

01{
02   "PlaceId":1818,
03   "ShowShutdownAllButton":false,
04   "Collection":[
05      {
06         "Capacity":8,
07         "Ping":66,
08         "Fps":59.974594,
09         "ShowSlowGameMessage":false,
10         "Guid":"8ad4c4b2-5c00-41f7-92f9-747b60382baa",
11         "PlaceId":1818,
12         "CurrentPlayers":[
13            {
14               "Id":0,
15               "Username":"A Roblox Player",
View all 36 lines...

To go to the link with Roblox scripts, you can use

1local HttpService = game:GetService("HttpService")
2local PlaceId = 1818 -- Crossroads
3local StartIndex = 0
4local Link = string.format("https://www.rprxy.xyz/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, StartIndex)
5local Data = HttpService:GetAsync(Link)
6print(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.

1local HttpService = game:GetService("HttpService")
2local PlaceId = 1818 -- Crossroads place id
3local StartIndex = 0 -- Start at server #0
4local Link = string.format("https://www.roblox.com/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, StartIndex) -- Set link with parameters
5local Data = HttpService:GetAsync(Link) -- Get data from link
6local DecodedData = HttpService:JSONDecode(Data) -- Decode the data
7-- print(Data)

Count the number of people in the servers

01local HttpService = game:GetService("HttpService")
02local PlaceId = 1818 -- Crossroads place id
03local StartIndex = 0 -- Start at server #0
04local Link = string.format("https://www.roblox.com/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, StartIndex) -- Set link with parameters
05local Data = HttpService:GetAsync(Link) -- Get data from link
06local DecodedData = HttpService:JSONDecode(Data) -- Decode the data
07local PlayerCount = 0
08for Index, Server in pairs(DecodedData["Collection"]) do
09    PlayerCount += #Server["CurrentPlayers"]
10end

Notice this only returns the first ten servers. This problem can be easily solved by integrating a loop.

01local HttpService = game:GetService("HttpService")
02local PlaceId = 1818 -- Crossroads place id
03local StartIndex = 0 -- Start at server #0
04local Link = string.format("https://www.roblox.com/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, StartIndex) -- Set link with parameters
05local Data = HttpService:GetAsync(Link) -- Get data from link
06local DecodedData = HttpService:JSONDecode(Data) -- Decode the data
07 
08for Index, Server in pairs(DecodedData["Collection"]) do
09    PlayerCount += #Server["CurrentPlayers"]
10end
11 
12for NewStartIndex = 10, DecodedData["TotalCollectionSize"], 10 do
13    Link = string.format("https://www.roblox.com/games/getgameinstancesjson?placeId=%s&startindex=%s", PlaceId, NewStartIndex)
14    local NewData = HttpService:GetAsync(Link)
15    local NewDecodedData = HttpService:JSONDecode(NewData)
View all 21 lines...

Hope this works!

0
Another question, which script do i put in? I want it to teleport to another game without it leaving roblox, and where do i put the script in? Bluejay20000 -11 — 4y
Ad

Answer this question