How would I make a renderstepped color-changing part that included playback loudness?

local part = workspace:WaitForChild('TRIAGE')
local setColor = Color3.fromRGB(75, 43, 255)
local clr_black = Color3.new() --empty constructor means black

res.Heartbeat:Connect(function()
	local song = _G.PlayingSong
	if song and song.IsPlaying then --make sure there's actually a song playing first
		local alpha = song.PlaybackLoudness * .001 --divide by 1000 to normalize the number since PlaybackLoudness is a number ranging from 0 to 1000
		part.Color = clr_black:Lerp(setColor, alpha)
	end
end)

this is what i have as my entire color change script. i did a few print functions and the hearbeat is working, the song just isnt playing.

Probably because the volume isn’t high enough. The color will only reach setColor when the sound is at its absolute maximum allowed by Roblox. You can change the way it normalizes the audio, maybe the set the cap lower?

local alpha = song.PlaybackLoudness * .01 --try dividing by 100 instead of 1000

tried messing with that, still just stays black. does it still maybe have to do with it not detecting the song?

Did you check if this enclosed snippet is running?

if song and song.IsPlaying then
... --the inside
end

If it isn’t try printing out _G.PlayingSong to see if the song’s even there
Also try printing out both alpha and song.PlaybackLoudness and see if the numbers are reasonable

yeah so i did put a print inside the ‘if song and song.isplaying’ part and it was working. for the alpha and playback loudness parts, how would i print those properly?

just put the variable inside the print function

local alpha = song.PlaybackLoudness * .001
print(song.PlaybackLoudnes)
print(alpha) --should be a number in between 0 and 1, keep in mind that 1 is the max volume

Print them out and see if the numbers are “appropriate”

1 Like

image
okay so the heartbeat part worked because it output this over and over, saying that my test audio isnt a valid member of sound

you misspelled PlaybackLoudness :skull:

oh my god lmao ok hold onnnnnnn

image
alright so its working, and prints the things

ok yeah that’s the problem WHY IS IT ZERO

do you hear the song playing in the game???

yeah i do -stretching because of the character limit-

while you can hear the song playing is it still printing out zeros? I actually have no idea what went wrong Sound.PlaybackLoudness

yeah i do still hear it while its printing zeros
if it means anything, the property of the sound says this before playing but i dont think it does
image


Do what it says, print it out in the command bar

print what exactly? like just print the ‘print(song.blahblah’ and ‘print(alpha)’ or the entire thing

Where are the sound instances located? Go pathfind to those music and then print its PlaybackLoudness

print(workspace.blahblah.blahblah.blahblah.music1.PlaybackLoudness)

print it repeatedly while the song is playing and you can hear it

1 Like

image

So then why does the script print zeros??? Can you go double-check to see if the song placed in _G is actually the one that’s playing?

	local song = sounds[math.random(1, #sounds)]
	song:Play()
	_G.PlayingSong = song
end

playRandomSong()

well heres my function, it looks like it should work properly, i personally dont see what would be wrong