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

Getting perfect value for PlayBackLoudness, but how?

I'm making a light that is changing color on the beat of a song. But how can I get the perfect > value so it will change on that moment.

while true do
    wait()																
    if game.Workspace.Sound.PlaybackLoudness > 100 then -- This one here 
        game.Workspace.ColorChangers.BrickColor = BrickColor.Random()
	game.Workspace.ColorChangers2.BrickColor = BrickColor.Random()
    end
end

2 answers

✓ Accepted answer

This is a bit long winded, but it works. I created a sound bar with four different lights that light up depending on how loud the song is at the time (Generally on the drops and each beat). It works quite well with most songs which are at 320kpbs which i'm guessing Roblox doesn't down the quality of a sound to 128 or anything.

But feel free to take this and have a mess about with it. just make sure this script is inside a model with four different bricks named Bar1-Bar4. It's completely your choice.

There are a few corrections that need to be done to make this a bit more convenient but I don't have the time at this very moment. it works fine anyway.

Hope it helps!

Bar1Light = script.Parent.Bar1.SpotLight
Bar2Light = script.Parent.Bar2.SpotLight
Bar3Light = script.Parent.Bar3.SpotLight
Bar4Light = script.Parent.Bar4.SpotLight
Song = game.Workspace.Music.Sound
MaxLoudness = 0
LightingFormula = 0

while true do
	wait(0.1)
	if Song.PlaybackLoudness >= MaxLoudness then
		MaxLoudness = Song.PlaybackLoudness
	end
	LightingFormula = MaxLoudness/4
	if Song.PlaybackLoudness <= LightingFormula* 1 then
		Bar1Light.Parent.BrickColor = BrickColor.new(1)
		Bar2Light.Parent.BrickColor = BrickColor.new(1)
		Bar3Light.Parent.BrickColor = BrickColor.new(1)
		Bar4Light.Parent.BrickColor = BrickColor.new(1)

	end
	if Song.PlaybackLoudness > LightingFormula* 1 and Song.PlaybackLoudness <= LightingFormula*2 then
		Bar1Light.Parent.BrickColor = BrickColor.new(1009)
		Bar2Light.Parent.BrickColor = BrickColor.new(1)
		Bar3Light.Parent.BrickColor = BrickColor.new(1)
		Bar4Light.Parent.BrickColor = BrickColor.new(1)
	end
	if Song.PlaybackLoudness > LightingFormula* 2 and Song.PlaybackLoudness <= LightingFormula*3 then
		Bar1Light.Parent.BrickColor = BrickColor.new(1009)
		Bar2Light.Parent.BrickColor = BrickColor.new(1009)
		Bar3Light.Parent.BrickColor = BrickColor.new(1)
		Bar4Light.Parent.BrickColor = BrickColor.new(1)
	end
	if Song.PlaybackLoudness > LightingFormula* 3 and Song.PlaybackLoudness <= LightingFormula*4-50 then
		Bar1Light.Parent.BrickColor = BrickColor.new(1009)
		Bar2Light.Parent.BrickColor = BrickColor.new(1009)
		Bar3Light.Parent.BrickColor = BrickColor.new(1009)
		Bar4Light.Parent.BrickColor = BrickColor.new(1)
	end
	if Song.PlaybackLoudness > LightingFormula*4-50 and Song.PlaybackLoudness <= LightingFormula*4 then
		Bar1Light.Parent.BrickColor = BrickColor.new(1009)
		Bar2Light.Parent.BrickColor = BrickColor.new(1009)
		Bar3Light.Parent.BrickColor = BrickColor.new(1009)
		Bar4Light.Parent.BrickColor = BrickColor.new(1009)
	end
end


^^^ I like that it works, but not really too, it doesnt set the lights off, please send me how to do that, thanks :D

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