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

LocalScript not getting workspace children, fix?

Hello all! I have a PlaybackLoudness script here, it's a more over-worked version, but functions when calling 1 variable in the problem of this script!

So the problem is on Line 5 I am trying to place all of the lights in a folder, in which this script is supposed to run on all of these parts at the same time!

I've used :GetDescendants() and :GetChildren() in which neither of these worked! I am wondering if there is a way to manipulate my code into making it function properly, or, if there is a function I am missing!

LocalScript Location in Stuido : StarterPlayerScripts

Thanks for everyones feedback! Any and all help is appreciated!

local Players = game:GetService("Players")


local LocalPlayer = Players.LocalPlayer
local ColorParts = game.Workspace.Lights:GetChildren() --[[ This is where I believe the problem is, but I could be wrong ]]--

local sound = game.Workspace:WaitForChild("MusicPlayer")

local maxLoudness = 500

while true do
	local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)
	if sound.PlaybackLoudness >= 300 then
		ColorParts.BrickColor = BrickColor.Random()
	end
	
	if sound.PlaybackLoudness <= 299 then
		ColorParts.BrickColor = BrickColor.new("Cyan")
	end
		
	if sound.PlaybackLoudness <= 250 then
		ColorParts.BrickColor = BrickColor.new("Lime green")
	end
	
	if sound.PlaybackLoudness <= 225 then
		ColorParts.BrickColor = BrickColor.new("Royal purple")
	end
	
	if sound.PlaybackLoudness <= 200 then
		ColorParts.BrickColor = BrickColor.new("Really blue")
	end
	
	if sound.PlaybackLoudness <= 175 then
		ColorParts.BrickColor = BrickColor.new("Gold")
	end
	
	if sound.PlaybackLoudness <= 150 then
		ColorParts.BrickColor = BrickColor.new("Institutional white")
	end
	
	if sound.PlaybackLoudness <= 125 then
		ColorParts.BrickColor = BrickColor.new("Really red")
	end
	
	if sound.PlaybackLoudness <= 100 then
		ColorParts.BrickColor = BrickColor.new("Dark blue")
	end
	
	if sound.PlaybackLoudness <= 75 then
		ColorParts.BrickColor = BrickColor.new("Neon orange")
	end
	
	if sound.PlaybackLoudness <= 50 then
		ColorParts.BrickColor = BrickColor.new("Burnt Sienna")
	end
	
	if sound.PlaybackLoudness <= 40 then
		ColorParts.BrickColor = BrickColor.new("Institutional white")
	end
	
	if sound.PlaybackLoudness <= 30 then
		ColorParts.BrickColor = BrickColor.new("Pastel Blue")
	end
	
	if sound.PlaybackLoudness <= 20 then
		ColorParts.BrickColor = BrickColor.new("Navy Blue")
	end
	
	if sound.PlaybackLoudness <= 1 then
		ColorParts.BrickColor = BrickColor.new("Black")
	end
	--ColorParts.BrickColor = BrickColor.Random()
	wait(0.05)
end

1 answer

Hello, BryanFehr!

I'm not sure if this would work but you can probably do something like this.

while true do
	for i,v in pairs(workspace:WaitForChild("Lights"):GetChildren() do
		-- the code inside of the loop here
	end
end

EDIT: I forgot to say something. Change everything in there to v.BrickColor

1 comment

0

This worked to a degree, but the script broke in a sense. And I don't understand as to why. The color changing didn't co-exist with the set music speeds, it just sort of made them change random colors every few seconds.

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