How can I get values out of a table?

How can I see the values in a table?

local TableTest = {1, "Onion", true, workspace.Baseplate}

for Index, Value in ipairs(TableTest) do
	print(Value)
end

Could you specify? :thinking:

2 Likes

Please describe in detail what you want to achieve. Do you want a UI to pop up, or do you just want to see them in the Output?

print(your_table) -- Disable Log Mode in Output before using.

Iā€™m putting player usernames into a table and i want to get 19 random usernames out of the table

Do you need a GUI for this, or do you just need to use the Output? If you just need the output:

local Players = game:GetService("Players")

local function Get_Random_Players_19()
	local Usernames = {}
	local Player_List = Players:GetPlayers()
	local Player_Count = #Player_List
	
	if Player_Count > 19 then
		while not (#Usernames == 19) do
			local Random_Selection = math.random(1, Player_Count)
			local Player = Player_List[Random_Selection]
			
			if not table.find(Usernames, Player.Name) then
				table.insert(Usernames, Player.Name) -- DisplayName can be the same for two or more players, use Name instead.
			end
		end
		
		return Usernames
	else
		return Player_List
	end
end

print(Get_Random_Players_19())
  1. Get the Players service.

  2. Use an empty table to put random names in.

  3. Check for player count.
    3a. If player count is above 19, continue.
    3b. Otherwise, return the list of players instead. Stop here.

  4. Fill the empty table with random names. Make sure no duplicates will be included.

  5. Return randomized table.

2 Likes