I need it for GUI.
I’ve tried to look for tutorials, but there are none.
local Players = game:GetService("Players")
local function GetPlayersNumber()
return #Players:GetPlayers()
end
print(GetPlayersNumber())
I forgot to mention that i need it on all servers, my bad
I don’t think you can do it using a localscript. But you can use a remotefunction and use the roblox api to get the number of active player.
Yes, can you show me example, please?
sure, create a remote function in replicatedStorage. after you will need to find a proxy because we cannot access on roblox ressource while we are on roblox. For me, i’ll use roproxy because it’s free. BUT remember that a proxy can send anything including nsfw messages so be aware of what you use. Then create a script on server side and put this:
local HttpService = game:GetService("HttpService")
local RemoteFunction = path.to.remote
local universeId = HttpService:JSONDecode(
HttpService:GetAsync("https://apis.roproxy.com/universes/v1/places/" .. tostring(game.PlaceId) .. "/universe")
).universeId
RemoteFunction.OnServerInvoke = function()
local decodedBody = HttpService:JSONDecode(
HttpService:GetAsync('https://games.roproxy.com/v1/games?universeIds=' .. tostring(universeId))
)
return decodedBody.data[1].playing
end
now on client side you can just do
local Remote = part.to.remote
print(Remote:InvokeServer())
Dont’t forget to enable HttpService (in command bar you can use game.HttpService.HttpEnabled = true
) and there we go!
SOURCES:
Sorry for late response. This has worked, with that i learnt how to use RemoteFunctions (while i was figuring out myself) thank you soo much!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.