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

can i ask about this bracket [ ] what its actually mean?

i just wondered what this bracket means in roblox coding because all of the video that i watching for scripting tutorials didn't tell what this bracket means so if anyone answer me about this question i would highly appreciate and thank you for answering my question

2 answers

In Lua, brackets can indicate a couple of things:

#Multi-line comments and strings

You can comment multiple lines using double brackets on the beginning and closing of your code. This is useful for temporarily disabling snippets of code in case you want to save them for later.

local part = workspace.Part

part.Touched:Connect(function(otherPart)
   print(1)
   --[[if otherPart.Name == "Test" then --this snippet will not run
      print(2)
   end]]
end)

You can do the same with strings (simply without the dashes, which indicate comments).

local str = [[
hi
how
are
you]]

#Table Indexing

Single pairs of brackets are used for indexing tables, like so:

local t = {"Hello"," world","!"}

local SelectedIndex = t[1] --the first key of the table
print(SelectedIndex) --prints "Hello"

You can also create new sections in tables. I tend to do this when storing player data:

local PlayerData = {}

game.Players.PlayerAdded:Connect(function(plr)
   PlayerData[plr.Name] = {
        AccountAge = plr.AccountAge --etc
   }
end)

##Resources:

Multi-line Strings

Multi-line Comments

Table Indexing

#Accept and upvote if this helps!

3 comments

0

u forgot things like workspace.Player[thing]

1

That is the same thing as indexing.

0

thank u phle

The brackets [] mean you are dereferencing a key in a table. In other words, go to the spot that is specified in the brackets, and get the value that is stored there.

-- Take this table as an example
tbl = {
	A = "something",
}

-- Now, we can access the data stored in 'A' by doing this:
print(tbl["A"]) -- this prints "something"

-- We can also set values in the table

tbl["B"] = "something else"

-- And we can also access this
print(tbl["B"]) -- this prints "something else" 

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