I’m currently attempting to get random user id’s from my roblox group. I’m also using these user ID’s for their character appearance and it will load it onto a random spawning NPC. I have a promising method to actually get the user id’s already, I need help to actually find a method to randomize this without being heavy on performance or anything.
This code actively finds 100 users from a group page and then goes onto the next page to find the next 100 users. This does work, but I need to readily be able to find a random user ID from the group and load their appearance on an NPC. Now I wouldn’t want to store the data because that would only give me the most recent users from the group which has over 30k members, and I wouldn’t want to just get certain sections from the group because this would leave out possible users.
local http = game:GetService("HttpService")
local url = "https://groups.RoProxy.com" -- proxy to use roblox api
local cursor = ""
local groupID = 10589628
while true do
print(cursor)
local get = http:GetAsync(url.."/v1/groups/"..groupID.."/users?cursor="..cursor.."&sortOrder=Asc&limit=100")
data = http:JSONDecode(get)
print(data["data"]); print(cursor)
cursor = data.nextPageCursor
if not cursor then break end
end
I guess my question is: How would I store this data? Should I store the data? How do I actually utilize this for spawning a random NPC with a random character from my group?
1 Like
If you want to randomize it you can get the min and max amount of pages and get a random page number. After, you can get the amount of data on the page and get another random number, 1-x. Then just use x as an index to get the user’s id.
I don’t think there’s an option to specify the page number
I think an issue with using this method is because I need the nextPageCursor which I think needs to be gotten from the first page and so on until it reaches the page number I’d like it to
Maybe you can save all of userid’s in a datastore, in a single key. And update the datastore every 10 minutes. You could loop through group members and if any of the member’s userid is in the datastore, which means the loop has reached the old save point, stop the loop and save to the datastore
I think I have a solution but I’m not such a genius to make it work… Basically I’ve been printing all of the nextPageCursor strings and I can run the GetAsync again using one of the nextPageCursors to retrieve data. My issue is I need to make a table containing all of these cursor strings and number them so that I can retrieve a random one or something
nextPageCursors are not saved for a long time, i think they only work for like 1 minute in roblox (might be wrong). But i’m pretty sure they are not saved infinitely
Could you help me out with some type of numbered table? This code creates all of the nextPageCursor’s rather quickly…
local http = game:GetService("HttpService")
local url = "https://groups.RoProxy.com"
local cursor = ""
local groupID = 10589628
while true do
print(cursor)
local get = http:GetAsync(url.."/v1/groups/"..groupID.."/users?cursor="..cursor)
data = http:JSONDecode(get)
--print(data["data"]); print(cursor)
cursor = data.nextPageCursor
if not cursor then break end
end
actually i just realized this might go on infinitely because theres no user limit number so its not getting account data
What do you mean by numbered table? Do you mean something like this
local Table = {
[0] = "String",
[1] = "String2",
}
Yeah I just can’t think of a good way to make this work properly lol
local datastoreservice = game.DataStoreService
local groupDatastore = datastoreservice:GetDataStore("InGroup")
local userIDS = {
1,
2,
3,
}
table.insert(userIDS, idOfTheNewPersonInGroup)
You can keep adding userids to the table if they don’t exist, and the moment the new user from http request is in the table, stop the loop and save to the datastore. This will create a list of userid’s in the datastpre
1 Like
I dont think there is a good way of getting a random user from all of the users in a group as for a big group you would need to request a list of a max of a 100 players to roproxy to move the cursor a lot of times and (i tested this) that is slow just on its own. You also cant specify a specific page or save cursors so the best way around this and still getting a kind of random userId i can think of is:
Sort by descending (“Desc”) (beacuse the last people might change so its not always the same from the start), set the limit to a 100 and save as many ids as you currently need by picking random from that list (also make sure that the system doesnt pick the same user multiple times). Also save the nextPageCursor as the new cursor and in a few seconds you can repeat this whole proccess and save some ids from the next page meaning new NPCs will be from the next page (and repeat this).
Its not a good system and you most likely wont get to a lot of users, but i think its the best you can do with roproxy without having to like go through all the pages and save all the ids first [whitch would take an eternity anyway]