I’m currently trying to figure out how to create an in-game player counter that would update every 5 seconds or so. My idea is to basically obtain the Game’s player count that’s displayed on the game’s page. So if it says there’s 200 players online, my menu will say that as well.
I want to expand this to including playlists as well (which would basically just be taking 2 or more places and combining the player counts of both.)
If anyone has any ideas on how I could achieve this, please let me know!
I am able to make it so that it shows how many people are in a single server. Although I am not sure how
to do you are wanting to do. So if you want it to say how much people are in a single server I can do that but not the total count.
Isn’t it through PlaceID and then finding the player count variable through web API?
If that’s the case, you could potentially combine all of the results from each place with a universe.
You could possibly achieve this by creating a web server and having that web server look at the page’s player count by looking at the HTML of the Roblox game page. When the web server receives a get request, it takes a look of it and sends back a response. The Roblox game sends the get request every few seconds or such.
You cannot do this through a script as it fails a trust check.
Not sure how to get an accurate player count but there is a way to get the player count on the website (I’m sure you’ve thought of this and have already ruled it off as inefficient but hey it’s a way).
You could use a proxy and send a GET request to your game page then parse out the playing thing.
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?
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.