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
In Lua, brackets can indicate a couple of things:
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]]
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)
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"