How to get every player's following count in a game and put the result number in player's leaderstats folder?

Hello! I’m a beginner scripter trying to make a script for a game!

  1. What do I want to achieve?

I want to get all the players in the game and get their following count to put in the player’s leaderstats folder.

  1. What is the issue?

The issue is that I don’t know how to get the userid of the player inside the game and put in the url (check below in example lua script) and then put the result in a player’s leaderstats.

  1. What solutions have I tried so far?

I tried looking in devforum to find others with similiar issues but I couldn’t really find any. And I’ve also tried learning more about httpservice because I don’t know all it’s proper functions yet,

for _, player in pairs(game.Players:GetPlayers()) do
table.insert(userIds, player.UserId)
end -- getting user userid from all players in the game and putting it in a table

local url = https://friends.roproxy.com/v1/users/%s/followings/count)
local HttpService = game:GetService("HttpService")

Any help would be much appreciated!

for _, player in pairs(game.Players:GetPlayers()) do
	local url = "https://friends.roproxy.com/v1/users/%s/followings/count"
	local urlWithUserId = url:format(player.UserId)
	local response = game.HttpService:GetAsync(urlWithUserId)
	local data = game.HttpService:JSONDecode(response)
	local followings = data.count
	print(player.Name, "has", followings, "followings!")
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.