Is there a way to do the same thing to two different objects at the same time?

I have a bunch of particle emitters inside two attachments(leftPupil & rightPupil), all of which are direction mirrors of each other. only difference would be their placement and name. Is there a way to change all the properties of one particle emitter and do the same exact thing to its corresponding mirror?
image

Clarification/TL;DR:
Say I have 2 blocks and I want both blocks to turn red and transparent, however, Im too lazy to write a script that goes, “change block one to red and transparent, THEN change block two to red and transparent”. Would there be a way to make a script that instead goes “change block one AND block two to red and transparent”?

1 Like

I personally don’t recommend you do this unless there’s a very specific reason to, but you could either utilize the Changed event, or listen to specific property changes via the GetPropertyChangedSignal function. Of course, you could just duplicate the Instance you are reading and just change the different properties (such as position). Regardless, it isn’t recommended you do this. Just loop through and change everything that needs to be changed.

1 Like

You could try something like this:

FlareProperties = {["Property1"]=3,["Property2"]="Hello world"}
changeEffectProperties("Flare", FlareProperties)

ShadeProperties = {["Property1"]=7,["Property2"]="Hello world!!"}
changeEffectProperties("Shade", ShadeProperties)

-- Continue making these for each effect

function changeEffectProperties(name,propertytable)
     local effect1 = RightPupil:FindFirstChild(name)
     local effect2 = LeftPupil:FindFirstChild(name)
     for property,value in pairs(propertytable) do
        effect1[property]=value
        effect2[property]=value
    end
end

But then again, it might just be better to do them one at a time as it is easier.

1 Like

– Used for table testing purposes
function printTable(tab)
for k,v in pairs(tab) do
print(tostring(k)…"="…tostring(v))
end
end
Would this work?

A simple way to do this is with a metatable. To apply a metatable to an object, you can do the following:
local object = {}
setmetatable(object, metatable)

After you have the metatable set up, you can just set the properties on the metatable and it will apply the properties to the object.

Hello, I attempted to use your idea of duplicating but editting one eyes particles then duplicating it to the other side but I still needed somewhere to save each particles base. Though it did effectively cut what I wouldve ended up doing in half. Though because of how particles work it does end up with this effect that Im not very fond of.

I probably should have mentioned this was for a rig…

Hi guys! Thank you so much for your ideas. I managed to make a breakthrough while reading your ideas in the comments. The solution I decided to use was using for i,v in pairs to find 2 instances that have the same name then changing both of them at the same time using the for i,v in pairs command. repeat for all the properties and I have a decently smooth transition for myself ! Since Im not deleting the particles completely, I had a little more freedom on what actually needs to be defined so I was also able to cut out properties that always stay the same.

If you have any more tips which will let me optimize my code please let me know so I can learn more from what I currently have.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.