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

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

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

✓ Accepted answer

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)

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

14 comments

0

It is the correct volume

0

yes, but i'm saying to not check against a number like 300. try using 10 instead of 300 with some loud audio

0

it doesnt work still

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.

0

it doesnt change starting from 1 dude

0

its not the sound

0

actually, PlaybackLoudness may not fire the Changed event. try using a while true do loop to check it

0

Thats not how Changed works, and I did use a loop

0

edited my answer

0

the sound is already playing and no

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

0

its returning as 0

0

quick question, is the sound playing? try doing sound:Play()

0

it is

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