Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how can i get the total amount of players playing my game?

i dont know a script for this, i just want to print out the number of players playing my game, no i dont mean game.Players:GetPlayers() i mean the overall amount in all servers, please help,

;-;

3 answers

✓ Accepted answer
local http = game:GetService("HttpService")
local gameid = game.GameId --the game id

local dat = http:JSONDecode(http:GetAsync("https://games.roblox.com/v1/games?universeIds="..gameid))

print("People playing ", dat[0].playing)

5 comments

0

it says HttpServices are not allowed to access roblox resources

0

You have to enable HttpServices, Go to Home -> Game Settings - > Options -> Http Requests

0

still says im not allowed to access roblox resources

0

Yes, this should be much simpler than my answer. Once you have enabled HttpServices, if it still doesn't work, try to restart roblox studio (Quit, then Reopen)

0

I just realised: You need to enable http services. To do that, add this line of code: game:GetService("HttpService").HttpEnabled = true

i found a fix thanks to BradNewTypical, i just needed to make the url a proxy.

local http = game:GetService("HttpService")

local gameid = game.GameId


local body = http:JSONDecode(http:GetAsync("https://games.rprxy.xyz/v1/games?universeIds=".. gameid))


local totalplrs = body.data[1].playing


print("Players In Total: ".. totalplrs)

Hi mahid786! We used to do game.Players.NumPlayers, but that is deprecated now. Instead, try this:

wait()
local NumPlayers = game.Players:GetChildren()
print(#NumPlayers)

To count all the children of the players, use #NumPlayers.

An example may be:

if #NumPlayers > 2 then
      print("There are more than 2 players!")
end

This checks if the amount of players are more than 2.

Another example can be:

script.Parent.Text = "There are "..#NumPlayers.. " in the server!"

That changes the text into: "There are " *number of players in the server* "in the server!"

I hope that my examples help you understand! If so, please accept my answer!

New Edit: I got this from the Developer Forum, so if you do not understand this, use this link.

local place_id = 0 --place id there
function players_online(place_id)
	local web = game.HttpService:GetAsync("https://www.rprxy.xyz/games/"..place_id)
	local player_text = string.find(web,"Playing") -- find the online players section
	local new = string.sub(web,player_text)
	
	local number_start = string.find(new,">") -- find where the number starts
	new = string.sub(new,number_start)
	
	local number_end = string.find(new,"<") -- find where the number ends
	new = string.sub(new,2,number_end-1)
	
	local players_online = string.gsub(new,",","") -- in case it's over 1000 players
	return tonumber(players_online)
end

Again, hope I helped.

3 comments

0

i understand it, but the thing is i want it so it gets the players in ALL servers not just one.

0

yh thats basically what i wanted thx

This discussion is preserved as it was. New answers, comments, and votes are closed.