Like, if you try to have a datastore for a server list, any item(s) you have will wipe any previous data.
I.e.
Before updating:
Server 1
Server 2
Server 3
After updating:
Server 1
Like, if you try to have a datastore for a server list, any item(s) you have will wipe any previous data.
I.e.
Before updating:
Server 1
Server 2
Server 3
After updating:
Server 1
This actually appears to be what I’m looking for.
I intend on supplying the API endpoint with a different PlaceID for each place, and then taking the player count from each place and combining them, giving me the “total” player count.
Same applies for each playlist.
Edit: Is there a version of this available for groups?
Do this (I’m on mobile so excuse any mistakes):
local CountStore = game:GetService("DataStoreService"):GetDataStore("PlayerCount")
local Count = 0
game:GetService("Players").PlayerAdded:Connect(function(Player)
Count = Count + 1
end)
game:GetService("Players").PlayerRemoving:Connect(function(Player)
Count = Count - 1
end)
while wait(30) do
CountStore:UpdateAsync(PlaceId, function(Old)
if Old then
return Old + Count
else
return Count
end
end)
end
I may have missed a few bits but it should get the idea across. It’s also 5AM and I’ve been up for over 48 hours now.
Although this may not be completely what you are looking for. I made a local script that checks for counts all the people in the server.
local PlayerCount = 0
game.Players.PlayerAdded:Connect(function()
PlayerCount = PlayerCount +1
end)
game.Players.PlayerRemoving:Connect(function()
PlayerCount = PlayerCount -1
end)
script.Parent.Text = (PlayerCount .. "Players Online")
Glad to have helped in a way.
There is a version of this for groups!
https://groups.roblox.com/v1/groups/{GroupID} <- This one to get a specific group via ID. This will get you all the info on a group (Including MemberCount)
http://api.roblox.com/users/{UserID}/groups <- Get a list of groups the player is in
Hope this helped!
A way to get a specific game in a group though?
Also, I haven’t really done much with HTTP stuff.
If I mange to get a specific place, how would I obtain just the player count?
Ok so you wanted an api for getting the group’s place. Sorry - misunderstood.
I actually was blissfully unaware that there was a master api for games.
https://games.roblox.com/v1/games?universeIds={UniverseIDs} <- This will allow you to get a game by UniverseIDs (it does allow multiple). It will return an array containing each universe with the respective player counts.
{
"data": [
{
"id": 0,
"rootPlaceId": 0,
"name": "string",
"description": "string",
"creator": {
"id": 0,
"name": "string",
"type": "string"
},
"price": 0,
"isExperimental": true,
"allowedGearGenres": [
"string"
],
"allowedGearCategories": [
"string"
],
"playing": 0,
"visits": 0,
"maxPlayers": 0,
"created": "2019-03-03T04:51:24.149Z",
"updated": "2019-03-03T04:51:24.150Z",
"studioAccessToApisAllowed": true,
"universeAvatarType": "MorphToR6",
"genre": "string"
}
]
}
Assuming you want to know how to process the data it’s pretty simple.
The data is stored in a JSON format (but it will return a table with HttpService:JSONDecode)
Here’s accessing the player count of the example:
local body = game:GetService("HttpService"):JSONDecode(res) --res would be the response from the server
local playerCount = body.data[1].playing
print(playerCount)
Expected Output: 0
(Havent tested, just typed it out here might be some complications…)
Thank you very much for your help!
Would like to thank everyone else who helped too!
What is 'res???
What do i do with “res”???
i keep getting this error
Plus i’ve put my Test game URL and i got this error
(Sorry for the late reply // necrobump)
res
is the response from the server – it’s the result of a GET request. Here’s an example:
local url = "https://games.roblox.com/v1/games?universeIds={UniverseIDs}"
local res = game:GetService("HttpService"):GetAsync(URL)
-- Then paste the other code
This obviously won’t work because:
However, this is the basics of how it works
So, in that case, how would the script be?
I just need to change the URL to my game URL or i need to do more things?
sorry i’m a bit bad at this topic
technically no, all that needs changing is the URL and pasting the rest of the code
but you need to 1 past the ID of the universe (NOT THE PLACE ID) and then proxy it (you can do it yourself – there are many tutorials in #resources for it).
Turn on HttpService permission in your game Settings. 3 years later…