Still confused, what is wrong with my script?

  • What the localscript is supposed to do:
    turn the dummy in workspace into one of the players friends
  1. I get no errors in the output
  2. the Dummy doesn’t turn into the players friend

Here is my localscript:

local usernames = {}
local friends = {}

local usernames = {}

local function iterPageItems(friendPages)
	for item, pageNo in iterPageItems(friendPages) do
		table.insert(usernames, item.Username)
		table.insert(friends, item.Id)
	end

	local friends = {}
	for item, pageNo in iterPageItems(friendPages) do
		table.insert(friends, item.Id)
	end

	local randomFriend = friends[math.random(#friends)]

	local npc = game.Workspace.npc
	local newHumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(randomFriend)
	npc.Humanoid:ApplyDescription(newHumanoidDescription)
end
  1. The script is located in StarterGui

What am I doing wrong?

Any help is appreciated!

Is it a Script or LocalScript? If its a script it should be located in the workspace or ServerScriptService

1 Like

Its a localscript so that each player who joins only sees their own friends, not someone elses.

Did you not run the function yet?

i don’t see the function:

iterPageItems()

fired.

Make sure to add the friendPages Variable that you got in the parentheses: ()

how do I run it. I’m confused.

just fire it.

iterPageItems()

It will give an error tho because you added a variable inside of the parentheses in the function. A variable is required for the function you created.

local usernames = {}
local friends = {}

local usernames = {}

local function iterPageItems(friendPages)
	for item, pageNo in iterPageItems(friendPages) do
		table.insert(usernames, item.Username)
		table.insert(friends, item.Id)
	end

	local friends = {}
	for item, pageNo in iterPageItems(friendPages) do
		table.insert(friends, item.Id)
	end

	local randomFriend = friends[math.random(#friends)]

	local npc = game.Workspace.npc
	local newHumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(randomFriend)
	npc.Humanoid:ApplyDescription(newHumanoidDescription)
end

iterPageItems()

??

What does your friendPages mean?

it gets all the users, accessories, usernames from the users on the Friend pages.

But I only see a variable there. Where have you written the part where you fetch that:

oh thats a good point. I didn’t do that. Don’t I Have to use HTTP service to get the friend pages?

You could use this to help you.