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

How do I make this script affect everything with the same name?

Asked by 6 years ago

I just finished making a script that causes a neon part to turn white when a song hits a loudness of 350 (Usually the beat). It works just as I have planned and the script is pretty basic. The one problem I am having is that It is set to affect a part called "Flicker" but whenever I copy and paste another one of these parts it only affects the original one. How do I make my Script affect every part with the name "Flicker"?

while true do
    wait()
        if game.Workspace.TrelloSound.PlaybackLoudness > 350  then
            game.Workspace.Flicker.BrickColor = BrickColor.new("White") else
            game.Workspace.Flicker.BrickColor = BrickColor.new("Gold")
        wait()
    end
end

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Personally I would use aFor Loop to loop through and find all the objects you want with whatever specific functions you want. I would put these "Clones" in a model to make it easier and more clean. In my example I would do that.

Code:

while true do   --Wouldn't recommend using a while loop unless you absolutely need to, but I don't know anything more to help you prevent using this
    wait()
    if game.Workspace.TrelloSound.PlaybackLoudness > 350  then
        for i,v in pairs(game.Workspace.Clones:GetChildren()) do --The model is named "Clones"
            if v.Name == "Flicker" then
                v.BrickColor = BrickColor.new("White") 
            end
        end
    elseif game.Workspace.TrelloSound.PlaybackLoudness < 350 then --Added in another check, didn't realize I didn't do that
        for i,v in pairs(game.Workspace.Clones:GetChildren()) do
            if v.Name == "Flicker" then
                v.BrickColor = BrickColor.new("Gold")
            end
        end
    end
end

If you have any problems or questions don't be afraid to comment and I would be glad to help. If this helped you don't forget to accept my answer. Also note that if you want to keep the parts in Workspace then just change it to your wantings.

0
So part of this works. They do change to white while in the model named "Clones". The one problem is that they do not revert back to gold when the volume is under 350. OVOFinessinq 21 — 6y
0
@OVOFinessinq Try it now yougottols1 420 — 6y
0
Is there a way I can make them all change at the same time, because what it does at the moment is change 1 at a time like a wave effect. OVOFinessinq 21 — 6y
0
@OVOFinessingq Now try again yougottols1 420 — 6y
View all comments (2 more)
0
Thanks for all the help. Greatly Appreciated OVOFinessinq 21 — 6y
0
No problem yougottols1 420 — 6y
Ad

Answer this question