Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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
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 joostie1 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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
Ad

Answer this question