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

How to use a script for multiple parts with the same name?

I have a model with multiple parts inside it with the same name and I am trying to use a single script to execute it. Is it possible to set the multiple parts to a single variable so I can run it easier? The code I attached is the audio part of the script. Model = Light3, Part = Bulb, Bulb contains the sound (BuzzingLight).

audioT = {}
for _, v in ipairs(workspace.Light3:GetDescendants()) do
    if v == "BuzzingLight" then
        table.insert(audioT, v)
        print(audioT)
        
    end

end
audioT.Volume = 0

1 comment

0

you could let it put a variable on true and then put a script in every part that says if variable = true then script,parent.(whatever you want to happen here) end, because then you can use script.parent for a part even if it has the same name. Hope this helps in anyway. greetings

1 answer

If you want to reduce the volume of sound you can do

for _, v in ipairs(workspace.Light3:GetDescendants()) do
    if v.Name == "BuzzingLight" then
        v.Volume = 0
    end
end

And if you want to access it later you can do

for _, v in ipairs(workspace.Light3:GetDescendants()) do
    if v.Name == "BuzzingLight" then
        -- do stuff to the BuzzingLight
    end
end

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