Ad
Log in to vote
0

Getting perfect value for PlayBackLoudness, but how?

Asked by 1 year ago
Edited 1 year ago

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

1 answer

Log in to vote
1
Answered by
Cuvette 242
1 year ago
Edited 1 year ago

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


Ad

Answer this question



Ad