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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
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)
0
it says HttpServices are not allowed to access roblox resources mahid786 41 — 4y
0
You have to enable HttpServices, Go to Home -> Game Settings - > Options -> Http Requests mixgingengerina10 223 — 4y
0
still says im not allowed to access roblox resources mahid786 41 — 4y
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) LennyPlayzYT 269 — 4y
0
I just realised: You need to enable http services. To do that, add this line of code: game:GetService("HttpService").HttpEnabled = true LennyPlayzYT 269 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

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)
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
i understand it, but the thing is i want it so it gets the players in ALL servers not just one. mahid786 41 — 4y
0
https://devforum.roblox.com/t/player-count-in-another-place/403105/8 Read this, maybe this is what you mean? https://developer.roblox.com/en-us/api-reference/class/MessagingService mixgingengerina10 223 — 4y
0
yh thats basically what i wanted thx mahid786 41 — 4y

Answer this question