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

How the tables actually work?

How the tables actually work?

I been Programming already some months and the hardest thing I have learned is the tables / arrays. I don't really get the concept, I know how to make basic stuff with this ones, but I want to go more out of the average.

What I know:

local tb = {

	 x = "Hello World!"

}

print( tb[1] ) -- ok
print( tb.x ) -- ok 

And that is the basic stuff I know. But I seen people that make things really complicated with this ones indexing key and that all weird stuff, and I want to be capable of doing the same.

Thanks for reading and any help is really appreciated, really.

If you want to give me a better explanaton and help me further and out of here you can contact me via Discord: SharkyBoy#2024

1 answer

An Explaination on Tables:

Tables store basic information and strings into one reference, where they can later be used for things like admin command storage etc.

For example, when I make any form of commands that require user input, I use a table to store a list of names for admins, and a list of commands for them to use.

Here is an example in a script:

local commands = {"commands","cmds"}

if script.Parent.Text == commands[1] then
	-- code for the command
end

Tables can also have parts stored, or models that you want to make an edit to later in a mass quantity, using for i,v in pairs(tablename) do, which is a simple way to edit those later. Make sure you use v.PathHere, as i is just a simple count of the items in the table.

Here is an example in a script:

local parts ={}
table.insert(parts, partpathhere)

for i,v in pairs(parts) do
	v.Name = "TablesTutorial" --just an example, not required.
end

To dive deeper you could read about this on the roblox developer forums.

1 comment

0

This doesn't really explain anything.

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