Why won't my script work?

The script is supposed to change the npc into a random friend on the users friendslist. Why won’t it work? The localscript is in the workspace. Please let me know.

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

local friends = {}
for item, pageNo in iterPageItems(friendPages) do
	table.insert(friends, item.Id) -- change store Id instead of Username
end

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

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

I get no errors in the output, but the dummy doesn’t change appearences.

1 Like

I suggest you do a bit of debugging and check that you are gathering your information properly. Try print the table friends and see if it has the data you are looking for.

1 Like

I get blue lines under the code

iterPageItems(friendPages)

I don’t know why or what the blue lines mean.

1 Like

What is iterPageItems defined as?

1 Like
function iterPageItems(pages)
	local currentPage = pages:GetCurrentPage()
	return currentPage:GetChildren()
end

But there is still a blue line under (friendPages) in for item, pageNo in iterPageItems(friendPages)

here is what i now have.

function iterPageItems(pages)
	local currentPage = pages:GetCurrentPage()
	return currentPage:GetChildren()
end

local usernames = {}
local friends = {}

local usernames = {}
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) -- change store Id instead of Username
end

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

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