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

How do you change the BickColor of a part depending on a sounds PlaybackLoudness?

Asked by 5 years ago

This is a ServerScript because on a LocalScript it didn't work either.

local sound = workspace.MusicHandler.Music

sound.Changed:Connect(function()
    if sound.PlaybackLoudness >= 300 then
        script.Parent.BrickColor = BrickColor.Random()
    end
end)

2 answers

Log in to vote
2
Answered by
pidgey 548 Moderation Voter
5 years ago
Edited 5 years ago

PlaybackLoudness is readonly. Changed will not fire unless a property is written to (correct me if I'm wrong). PlaybackLoudness only updates itself. Also note that Changed also does not fire in physics-related changes. You will need to look for changes constantly. I suggest using the Heartbeat event of RunService because PlaybackLoudness runs with the server. A while-true statement would also be fine.

local RunService = game:GetService("RunService")

local sound = workspace.MusicHandler.Music

RunService.Heartbeat:Connect(function()
    if sound.PlaybackLoudness >= 300 then
        script.Parent.BrickColor = BrickColor.Random()
    end
end)
Ad
Log in to vote
0
Answered by
megukoo 877 Moderation Voter
5 years ago
Edited 5 years ago

PlaybackLoudness will normally never be above 300 (unless the Volume is super loud.)

Try numbers like 10 and 20 to check the loudness.

Also, sound.Changed may not occur when the PlaybackLoudness changes due to how often it can fluctuate. You may need to use a while loop to check it.

Example:

local sound = workspace.Sound

sound:Play()

while true do
    print(sound.PlaybackLoudness)
    wait(0.5)
end
0
It is the correct volume ReallyUnikatni 68 — 5y
0
yes, but i'm saying to not check against a number like 300. try using 10 instead of 300 with some loud audio megukoo 877 — 5y
0
it doesnt work still ReallyUnikatni 68 — 5y
0
again, try going lower until you find a match. PlaybackLoudness is dependent on the audio. try starting from 1 until you find a suitable number. megukoo 877 — 5y
View all comments (10 more)
0
it doesnt change starting from 1 dude ReallyUnikatni 68 — 5y
0
its not the sound ReallyUnikatni 68 — 5y
0
actually, PlaybackLoudness may not fire the Changed event. try using a while true do loop to check it megukoo 877 — 5y
0
Thats not how Changed works, and I did use a loop ReallyUnikatni 68 — 5y
0
edited my answer megukoo 877 — 5y
0
the sound is already playing and no ReallyUnikatni 68 — 5y
0
i've just tested it in Studio myself, PlaybackLoudness does not influence the Changed event in a Sound. you need to use a loop megukoo 877 — 5y
0
its returning as 0 ReallyUnikatni 68 — 5y
0
quick question, is the sound playing? try doing sound:Play() megukoo 877 — 5y
0
it is ReallyUnikatni 68 — 5y

Answer this question