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

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

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

✓ Accepted answer

Personally I would use a For 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.

6 comments

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.

0

@OVOFinessinq Try it now

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.

0

@OVOFinessingq Now try again

0

Thanks for all the help. Greatly Appreciated

0

No problem

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