Get the amount of players in a game

Hey! So im working on a game, and i want to grab the amount of players in a game in that specific universe, and make it show up on the text label. Here is an example of a picture.
image

here is the script. I would be grateful if anyone can help me modify this script to work:

 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

while wait(0.01) do
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)
script.parent.text = "Players : "..new

end

2 Likes

Did you script this? The only reason I asking is it seems like you just copied it.

Unfortunately I didn’t, but I’m currently looking for a solution to modify this. “I would be grateful if anyone can help me modify this script to work”

One way to make a guis text say the amount of players in a game is:

while wait() do
local amount = game.Players:GetPlayers()
script.Parent.Text = #amount
end

I suggest instead of just copying someones work you learn how to script yourself.

I appreciate the help, but I am trying to get the players from another game to show up on the text.

I am a little bit experienced in scripting, but this is a hard topic, and I haven’t seen anyone really cover it.

Are you receiving any errors from the script?

Yes, but just one im pretty sure.

Sorry if its a bit blurry. I tried cropping only that output statement out

You are missing an end to close the do block.

Okay. How do you think I can make this script successful in grabbing the amount of players from another game to show up on the gui in the same universe?

You should ask the person who created the script to help you as it is their script.

while wait(0.01) do 
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)
script.parent.text = "Players : "..new

end

i already have an “end”

You can not have anything else after the return statement.

Why are you doing GetAsync every 0.03 seconds (wait has a minimum of 0.03 seconds)? Also, why are you doing it on the client?

Can you reword this? I’m sorry, as to i’m not that experienced in roblox scripting.

I’m not sure if this would help, but I’d recommend you look take a look at this. Review your in-game stats with the GameStatsAPI!

1 Like
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


while true do
	print(players_online(000000))
	wait(6)
end

those weird " things are so annoying