Help with DList

I’m currently using a DList which loops through the players online then adds an option to the list dependent on the player’s name.
Lets say line 1 is bot01 and line 2 is cat
how would I make it so I can run something on the selected player and retrieve the name that is on that line?

What kind of list is it? A DListView? A DListLayout?

Ah my bad, DListView.

Try using

DListView:GetLine, then

Panel:GetValue on that line (hang on, I’ll test some stuff to get a decent example for you)

Currently using GetSelectedLine
Returns num, 1, 2, 3…

Try something like this:

local addedplys = {}

for k,v in pairs( player.GetHumans() ) do -- I assumed you added players using something like this
	list:AddLine( v:GetName() ) -- add the line
	addedplys[k] = v -- add the player to the table

-- do this stuff later when you want to get the selected player to do stuff with them
local ply = addedplys[ list:GetSelectedLine() ]
ply:ShowProfile() -- for example

That should work unless the list is sortable, if the list is sortable, you’d have to do something else like this:

local function GetPlayerFromNickName( nick )
    for k,v in pairs( player.GetHumans() ) do
        if v:Nick() == nick then return v end

local sel = list:GetSelectedLine()
local line = list:GetLine( sel )
local str = line:GetValue(1) -- this returns the first value you entered for the line, hopefully the player's nickname in your case
local ply = GetPlayerFromNickName( str )
ply:ShowProfile() -- for example

The problem with doing something like that is that if a player has the same nickname as another, the nickname function won’t work properly