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

How can I add a number of parts to one variable ?

Hello I try to add 4 objects to one variable. My script is like this:

shopManager.Counter = script.Parent.Counter0 and script.Parent.Counter1 and script.Parent.Counter2 and script.Parent.Counter3

When I only add two object it works. But at four objects it do nothing. Why is this so ?

Sry for my englisch ^^

1 answer

✓ Accepted answer

Variables can only contain one value. Here you are using an and operation, which will return a boolean data type.

With Roblox lua, as you have some instance found using script.Parent.Counter0 this will return true.

Your expression will probably be evaluating to true and true and true and true and true which is true, so shopManager.Counter would contain the value true rather than an object/instance.

You should probably use an array/dictionary in index these instead.

e.g. shopManager.counter = {script.Parent.Counter0, script.Parent.Counter1, script.Parent.Counter2, script.Parent.Counter3}

And to read these later on you would have to access a specific item in the array such as shopManager.counter[1]

This will probably be of help: https://developer.roblox.com/en-us/articles/Table

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