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

Can a variable be given more than one value?

For an example can I do:

local hat = hit.Parent:FindFirstChild("Noob", "Pro", "Bob")

Or is this not possible? All help is appreciated!

4 answers

You need to use a table, you will need this code:

hat = {"Noob" , "Pro" , "Bob"}

Then you need to use for i,v in pairs stuff, pls refer to tables in the wiki.

Click here to go to the wiki post about tables.

No.

Imagine I had something like

friend = (Alice, Bob, Eve)

How could I answer questions about friend?

What is friend.Name? Answering just "Alice" or just "Bob" is wrong. Should we answer all three? In what order? What does, e.g., friend.Name:sub(#friend.Name) (the last letter of their name) mean? Is it ("e", "b", "e")? Or are the two friends different, meaning it's ("e", "i", "i", "", "b", "b", "", "e", "e")? Do we discard duplicates?

Is friend == Alice true, false? Or is it perhaps (true, false, false)?

If I insert friend into a list,

local list = {}
table.insert(list, friend)

How big is list afterwards? Does it contain 3 things, or 1? Is there an order of those things?


A value is a single object, but that object may be a collection of other values.

For example, a list or set of values can be represented as a table:

friends = {Alice, Bob, Eve}

We can now provide meaningful answers to these questions.

friends doesn't have a name, but each friend has a name:

for _, friend in pairs(friends) do
	print(friend.Name) --> Alice, Bob, Eve
end

friends == Alice is of course false, but we could write a function that lets us ask contains(friends, Alice) -- is Alice included in our list of friends?

Adding friends to a list just adds one thing -- this group of friends. But we can explicitly add each one individually, too:

for _, friend in pairs(friends) do
	table.insert(list, friend)
end

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