How to return "Name" instead of the number in a table?

  1. What do you want to achieve?
    In the title.

  2. What is the issue?
    The issue is that it returns 1 and 2 without the .Name.
    Screenshot below.

  3. What solutions have you tried so far?

I tried putting .Name, but other than that I am so tired I’m clueless.

2 Likes

Update:

I tried going back to putting content instead of filename and it still didn’t work. It returned tablex(NUMBERS AND RANDOM LETTERS)

image

local listFrame = script.Parent
local fileTemplate = listFrame.FileTemplate

local function displayFiles(files)
	local templateHeight = fileTemplate.AbsoluteSize.Y
	local nextPosition = 0

	for fileName, content in pairs(files) do
		local fileInstance = fileTemplate:Clone()
		fileInstance.Name = fileName
		fileInstance.Text = tostring(content)
		fileInstance.Parent = listFrame
		fileInstance.Visible = true

		fileInstance.Position = UDim2.new(0, 0, 0, nextPosition)
		nextPosition = nextPosition + templateHeight
	end
end

local function clearList()
	for _, child in ipairs(listFrame:GetChildren()) do
		if child:IsA("Frame") and child ~= fileTemplate then
			child:Destroy()
		end
	end
end

local function updateList()
	while true do
		game.ReplicatedStorage.getFiles:FireServer()
		wait(5)
	end
end

game.ReplicatedStorage.getFiles.OnClientEvent:Connect(function(files)
	clearList()
	displayFiles(files)
	print(files)
end)

game.ReplicatedStorage.getFiles:FireServer()

coroutine.wrap(updateList)()

When iterating through a table, index which in your case is called filename would be the name of the index, if you just removed the .Name part, however its name can just be a set of numbers which is known as an Array, but a table with the index as a Phrase or string, is known as a Dictionary.
The value part which is called Content would be the value of the index, if its an Instance, you can say value.Name, but if not, you would just have to refer to it as value.

1 Like

I assume that the files is referring to the Player-3026... table. So fileName will refer to the index of the table, and content will refer to the content inside 1 table and so on. If you would like to get the Name section of the table that you are looping through, you can try content["Name"]

1 Like

Bless you. Curse30CharacterLimit

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.