Sound Loudness Always Returning 0?

I want to be able to decode songs and convert them to strings for future reference, which is what i’m trying to do now, but it’s not working because the sound loudness seems to be stuck at 0, despite the song seeing to be playing (judging by the running of the while loop).

Any help?

Server Script:

local beatModule = require(game.ServerStorage.BeatModule)
beatModule.DecodeSong(script["Robotic Dance C"])

Module

local BeatModule = {}


BeatModule.DecodeSong = function(Song)
	Song:Play()
	local counter = 0
	local decoderTable = {}
	local function checkAndReturnSlotPos(playbackLoudness)
		if playbackLoudness > 0 and playbackLoudness <= 100 then
			decoderTable[counter] = "A"
		elseif playbackLoudness >= 101 and playbackLoudness <= 200 then
			decoderTable[counter] = "B"
		elseif playbackLoudness >= 201 and playbackLoudness <=300 then
			decoderTable[counter] = "C"
		elseif playbackLoudness >= 301 and playbackLoudness <= 400 then
			decoderTable[counter] = "D"
		elseif playbackLoudness >= 401 and playbackLoudness <= 500 then
			decoderTable[counter] = "E"
		elseif playbackLoudness >= 501 and playbackLoudness <= 600 then
			decoderTable[counter] = "F"
		elseif playbackLoudness >= 601 and playbackLoudness <= 700 then
			decoderTable[counter] = "G"
		elseif playbackLoudness >= 701 and playbackLoudness <= 800 then
			decoderTable[counter] = "H"
		elseif playbackLoudness >= 801 and playbackLoudness <= 900 then
			decoderTable[counter] = "I"
		elseif playbackLoudness >= 901 and playbackLoudness <= 1000 then
			decoderTable[counter] = "J"
		end
	end
	if not Song.isLoaded then
		Song.Loaded:Wait()
	end
	while Song.IsPlaying do
		local randomNum = math.random(1,3)
		counter += 1
		local sound_Loudness = Song.PlaybackLoudness
		print("Sound Loudness: "..sound_Loudness)
		checkAndReturnSlotPos(sound_Loudness)
		wait()
		print(decoderTable[counter])
		if randomNum == 1 then
			wait()
		elseif randomNum ==2 then
			wait(0.5)
		else
			wait(0.5-0.2)
		end
	end
	
	print("Decoded...")
	local previousString = ""
	for i = 1, #decoderTable do
		previousString = previousString..decoderTable[i]
	end
	print(previousString)
end
return BeatModule

Is it running on a server script? cause If it is, you’ll have to run it on client.

1 Like

On a server script, Clearly it returns 0 from a server script. Only client has a capability of returning the actual value of loudness.

1 Like

You’re only saving the loudness once, it’ll return the loudness of the audio when the variable was assigned, remove the “local”

1 Like

Ok thank you! I should’ve seen that I was resetting the variable every time

Np, you should mark a reply as solution if it worked for you :slightly_smiling_face:

1 Like

You also helped me! Thanks for letting me know that!

1 Like