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)
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)
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
This discussion is preserved as it was. New answers, comments, and votes are closed.
14 comments
It is the correct volume
yes, but i'm saying to not check against a number like 300. try using 10 instead of 300 with some loud audio
it doesnt work still
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.
it doesnt change starting from 1 dude
its not the sound
actually, PlaybackLoudness may not fire the Changed event. try using a while true do loop to check it
Thats not how Changed works, and I did use a loop
edited my answer
the sound is already playing and no
i've just tested it in Studio myself, PlaybackLoudness does not influence the Changed event in a Sound. you need to use a loop
its returning as 0
quick question, is the sound playing? try doing sound:Play()
it is