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

What's the difference between [""] and . when getting the key of a table?

local Table = {
	Name = "Apple";
	Consumable = true;
}

print(Table["Name"])
print(Table.Consumable)

It will print Apple and true

I want to know, is there a difference between using Table["Key"] and Table.Key?

1 answer

✓ Accepted answer

You can get names with gaps in them using [""] and if you don't want to put in that effort you can just use . with no gaps in the variable.

example:

local t = {["lol hi"] = true}
print(t["lol hi"])

then ofc

local t = {lol_hi = true}
print(t.lol_hi)

what wouldn't work is:

local t = {lol hi = true}
-- or
local t = {["lol hi"] = true}
print(t.lol hi)

2 comments

0

Actually [""] can be used to get names with any illegal characters

0

Ah right, thanks!

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