Trying to loop through a table, though it only index's table[1]

For an odd reason, the table I am trying to loop through is only returning table[1] (the table is from Player:GetFriendsOnline())

My Script:

-- variables --
for i, friend in pairs(game.Players.LocalPlayer:GetFriendsOnline())
    -- no need to show the code here, this is a looping problem, not a data problem.
end

The code you posted is perfect. Beautiful, even.

The problem is probably within the loop. Try stepping through your code line-by-line with the lua debugger and watching the variables as they change.

You can also print out the whole table and see what it outputs.

But the code works, two of my friends are online, but only one shows up, and the correct data is displayed on the gui.


This is not an issue for me

there are reasons for code to not error but not continue after 1 recursion, the function is not broken so you’ll need to post the code.

Could this be the problem?:

local template = script.Parent.Frame
local playerDisplay = template.Display

-- insert loop here
    template:Clone()
    playerDisplay.Text = friend.DisplayName
--

I dont think this would solve the issue you are having but i suggest using ipairs in this case + use PlayerGui

I would maybe just post the entirety of the code. Would make it faster if we could just confirm it’s not a problem.

What does #LocalPlayer:GetFriendsOnline() print?

It just prints the number of friends currently online since run.

Are you assigning an sort of position to these GUIs? If not then I think you are just cloning the same GUI in one position multiple times. This would mean that the last clone would be the only one showing. Maybe add a number for every time you add a frame, then multiply that by the height/width (depending in horizontal or vertical style) of the GUIs and then place the newly cloned frame in that position. This concept is flawed but its a starter.

You can use a UIListLayout constraint to automatically do it for you.

I found the issue! Just forgot to add better variables.

You know, this is why you should have given us all of your code. We would have never found the issue because you simply covered it up with — variables

2 Likes