Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Solved] A family tree for friends list is too complicated, I need some help.. Can you help me?

So basically I have a user, "greatneil80", the endpoint is "SomeRandomGuy", I want it to retrieve a tree that tells you greatneil80-->RandomGuy-->another random guy-->SomeRandomGuy, as many times until it reaches its endpoint. My issue is, I am finding it hard to create threads of new tables and index them after running the function again, I would love some help, here is my code:


local User = "greatneil80"
local Find = "SomeRandomGuy"
local Tree = {}

local function Got_User()
	local Players = game:GetService("Players")
	local function iterPageItems(pages)
		return coroutine.wrap(function()
			local pagenum = 1
			while true do
				for _, item in ipairs(pages:GetCurrentPage()) do
					coroutine.yield(item, pagenum)
				end
				if pages.IsFinished then
					break
				end
				pages:AdvanceToNextPageAsync()
				pagenum = pagenum + 1
			end
		end)
	end
	local userId = Players:GetUserIdFromNameAsync(User)
	local friendPages = Players:GetFriendsAsync(userId)
	local usernames = {}
	for item, pageNo in iterPageItems(friendPages) do
		table.insert(usernames, item.Username)
	end
	for _, v in pairs(usernames) do
		if v == Find then
			print("FOUND USER!!! -->", v)
		else
			Tree[User] = v
			User = v
		end
	end
end

Got_User()

I really have no clue how to set this up, I'd appreciate help!

1 answer

I won't post code because I worked hard but what I did was get the users friends and their friends, then I got the other users friends and their friends and paired them up to see who is friends with who, if there's a link, it will print otherwise it won't.

1 comment

0

If anyone managed to come here by chance, I did a take #2 and take #3 along with another remake, #4 with the same concept. The code was somewhat messy but each time I rewrote it, it gave me more options and looked neater than the latter

This discussion is preserved as it was. New answers, comments, and votes are closed.