How would I do this?

I want to make a table which basically changes all properties of the stuff in the table when it is iterated though.

Here is an example:

Also, this table will have properties for more than one instance

local Table = {WaveSpeed = {speed = 2, original = 1}}



for _, property in pairs(Table) do
— how would I be able to change the property here?
end
1 Like

you would set up the table like this

local Table = {["WaveSpeed"] = {["speed"] = 2, ["original"] = 1}}

then you could cycle through them like this:

for Name, Property in pairs(Table) do
     if type(Property) == "table" then
          for InsideName, InsideProperty in pairs(Property) do
               -- Edit Values here
          end
     else
          -- Edit First values here (If wavespeed had a set value, ex. ["WaveSpeed"] = 3)
     end
end
1 Like

That most likely is the solution he is looking for, however, doing:

is no different than doing:

BTW

1 Like

Although this would be the solution. I don’t think I worded it correctly.

The main issue I’m having is that if I want to change a property in (let’s say terrain Waterspeed) to a new value (1) THEN, I have a random part in workspace, and I change the parts transparency to 0.5, how would I do that? If I try to make any value of the table the thing (like workspace.Terrain.WaterWaveSpeed) it will turn into a number and you can’t change the actual property, just the number.

I don’t believe it’s possible to write into a table with that method but you can read from it, with code like the following

local Table = {
	["Value"] = {
		[1] = workspace.Baseplate.Size
	}
}

print(Table.Value[1]) -- prints the size of the baseplate size

But writing property values through a table is not possible

You could try this, have your table as follows:

local Table = {
    [game.Workspace.Terrain] = {
        ["WaveSpeed"] = {
            ["speed"] = 2, ["original"] = 1
        }
    },
    [game.Workspace.RandomPartName] = {
        ["Transparency"] = 0.5
    }
}

Then Loop it like this:

for Object, Properties in pairs(Table) do
     for PropertyName, PropertyValue in pairs(Properties) do
        if type(PropertyValue) == "table" then
            -- Edit Values Here
        else
            Object[PropertyName] = PropertyValue
        end
    end
end

That should work!

works perfectly, thanks!

although i do have one question:

what does

if type(Property) == "table" then

do?

This checks if the property is a table, for our case, Property will either be a table:

(Here Property is the Table WaveSpeed Stores)
However, in our part, the transparency is just a number, and not a table:

1 Like

it provides an error: Unknown global property. do I need to create a “Property” variable or is this something else?

Try it now, I meant to put PropertyValue and not just Property. My bad!

1 Like

yeah thats what i thought, but no worries! once again, thanks for helping!

1 Like