Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can anyone help me with this table bug?

local DaTable = {TimeString = "19/6/2016",EnemyString = "Hi" ,OfficialBool =true,WinBool = true}
local NewTable = {}
table.insert(NewTable,1,DaTable) 
print(table.concat(NewTable[1], " "))

What it prints out is "" <--- Equal to nil How do i fix that?

1 answer

✓ Accepted answer

Take a look at the wiki explanation for table.concat:

"Given an array where all elements are strings or numbers..."

DaTable doesn't fit either of those requirements. It's not an array, and it has both booleans and strings. That's why it doesn't work with table.concat. Other than that your code is fine.


You could write your own table.concat function if you wanted to:

function concatenate(table)
	local str = ""
	for key, value in pairs(table) do
		str = str .. " " .. tostring(value)
	end
	return str
end

2 comments

0

When i do print(DaTable[1]) it prints out nil

0

DaTable[1] IS nil. It's a dictionary, so it doesn't have numbers for keys. You have to use the keys you gave it: DaTable["TimeString"] or, alternatively, DaTable.TimeString

This discussion is preserved as it was. New answers, comments, and votes are closed.