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

What do [] brackets do and the other ones if my understanding is wrong?

I have seen all kinds of brackets these : {} I think are for tables these () I think are for parameters . BUT THESE [] I cannot understand. I don’t get what [] bracket do.

3 comments

0

I'm not sure on the proper reason as to why but I have seen them used, and used them in tables for callable number names for tables, alongside getting to the child of an instance if that instance has a name with a space. I.E workspace["Roblox Headquaters"]

0

You can use it for either finding a child or getting a poperty of an instance.

4 answers

✓ Accepted answer

A lot of times it's used to get certain stuff out of tables or dictionary's, but it can also be used to find a child inside of Workspace or another place, It can find children with spaces

Dictionary example: (Tables and Dictionary's are almost the same}

-- Make the dictionary using the [] brackets to name them!
local fruitDictionary = {
	["Bananas"] = "Not my favorite";
	["Apples"] = "Pretty good";
	["Eggplants"] = "Sus";
}

-- Print the Eggplants
print(fruitDictionary ["Eggplants"])
-- When you run the script it should say sus!

Children Example

workspace["My Part that has a space"].BrickColor = BrickColor.new("Bright green")

Hope this answered your question!

Square brackets are used to reference items in a table. For example:

local table = {12, 41, 62}

print(table[2])  --prints 41

table[2] = 123

print(table[2])  --prints 123

print(table[1])  --prints 12

They can also be used to reference table keys that are strings:

local table = {
	["oranges"] = 152,
	["apples"] = 127,
	["potatoes"] = 4
}

print(table["apples"])  --prints 127

Square brackets can be used to find things you may not be able to without using them. another use is for picking a certain item in a table

part = workspace.my part -- This will not work
part = workspace["my part"] -- this will work

mytable = {one, two, three}

mytable[2] = "seven"

I hope this makes sense

hey you! have you ever heard of enes? if you are in trouble, better call enes!

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