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

How would I print my table's values?

local presetbans = {
	["ApocalypseRising927"] = {"Testing"},
	["Interzone"] = {"Testing Also"}
}

There is my table for a ban system. I tried many different ways, but I could print the 'reasons'.

I can only seem to print the names, how would I get the names' "reasons/values"? Thanks for help! :D

2 answers

✓ Accepted answer

Well, you'd first want to change them to a value format, currently you have them as a table.

local presetbans = {
    ["ApocalypseRising927"] = "Testing",
    ["Interzone"] = "Testing Also"
}

now with the modified code, this means ApocalypseRising927 is the index of value Testing. Now to print out the value, we would iterate through the table's contents using the pairs function.

local presetbans = {
    ["ApocalypseRising927"] = "Testing",
    ["Interzone"] = "Testing Also"
}


for index, value in pairs(presetbans) do
	print(index,value)
end

technically this script would print out both the indexes and values.

local presetbans = {
    ["ApocalypseRising927"] = {"Testing"},
    ["Interzone"] = {"Testing Also"}
}

print(presetbans["ApocalypseRising927"][1])
print(presetbans["Inerzone"][2])

If you wanted, you could just do ["Name"] = "Testing",

That way you can just say print(presetbans["Interzone"]) and automatically get your reason but this should work.

You basically have a table inside of a dictionary inside of a table.

So print(presetbans) would print the table.

print(presetbans["Interzone"]) Would print the table inside of this dictionary.

For the data in the table we add the [1] to reference the reason inside of that table.

2 comments

0

Interzone* Apologies.

0

Should be "print(presetbans["Interzone"][1])" not 2, as you want to print the reason which is the first value

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