Audio Visualizer Dev product not working correctly?

Ive been working on a club-type game where the place changes colours depending on the beat of the song, and it works quite nicely so far!

However, It all went down-hill when I added a queue for songs requested via developer product.

Code
local Playlist = game.Workspace.Playlist:GetChildren()
local Deb = true
local Queue = {}
function AudioPlayback (Audio)
	local seconds = 0
	Audio:Play()
	local h,s,v = game.Workspace.ColourOfChoice.Color:ToHSV()
	
	while Audio.TimeLength>seconds do
		for i,v in pairs(game.Workspace.AudioVisualizedParts:GetChildren()) do
		v.Color = Color3.fromHSV(h,s,Audio.PlaybackLoudness/100)
		v:FindFirstChild("PointLight").Color = v.Color
		end
		wait(0.1)
		seconds = seconds + 0.1
		
		--print(Audio.PlaybackLoudness)
	end
		
end

game.ReplicatedStorage.Remotes.RE.OnClientEvent:Connect(function(Key,Audio)
	if Key == "AudioTransfer" then
	Queue[#Queue+1] = Audio
--	for i,v in pairs(Queue) do
--		print (i,v)
--	end
	return Queue
	end
end)

wait(5)

while Deb == true do
	local AudioChosen = Playlist[math.random(1,#Playlist)]
	
	for i,v in pairs(Queue) do
		print (i,v)
	end
	
	if #Queue > 0 then
			
		for i,v in pairs(Queue) do
			local AudioSound = "rbxassetid://"..v
			print(AudioSound)
			local Sound = Instance.new("Sound")
			Sound.SoundId = AudioSound
			Sound.Parent = game.Workspace.Playlist
			AudioPlayback(Sound)
			Deb = false
			wait(Sound.TimeLength)
			table.remove(Queue,i)
			print(Sound.TimeLength)
		end
	
	else
	Deb = false	
	AudioPlayback(AudioChosen)
	
	wait(AudioChosen.TimeLength)
	Deb = true
	end
	game.Workspace.ColourOfChoice.BrickColor = BrickColor.Random()
	
	print("Audio Stopped")
end

Here’s the issue; I have a folder in workspace named “Playlist”, and without the queue, I wanted it to randomly shuffle thru the audios I have placed inside of it - which works fine and changes the colours around it accordingly.

The issue:
When I purchase the test developer product, it plays the audio and plays all the songs in the queue - great! However, for some reason, it’s not registering in the function properly to change the lighting and part colours values. (Yes I realise I didn’t add a deb = true at the end of my for loop, but that was for testing purposes)

Another this is, the for loop isnt waiting the song timelength before continuing on, I’ve even printed it and it prints an actual number.

I know it’s a lot to ask, and if you need to see how I process the recipt and get the audio ID requested, please comment, I can supply that. I really can’t think of the problem rn!

Thanks so much!

(PS this is a local script)

EDIT: I found an issue, no clue how it happened, but in the AudioPlayback function, the timelength for the queued song is 0, and I have no idea why

Hello there,

We will try and make an attempt to fix this issue for you, however additional information is required.

Perhaps something within your developer product script doesn’t send back information about the song’s timelength?

That’s why it doesn’t work anyways, the script thinks that the timelength of the song already reached 0 and because of that it simply doesn’t work because it thinks that the song is finished while it’s not.

You should take a look at how you handle these song requests throught developer products.

Additionaly are you getting any errors in your output in the process of purchasing the developer product?

More information is required for us to be able to help you, like how you handle these song requests from the developer product in the script/local script for example, we have no idea how you handle the purchases.

Hope that we can help you. :slightly_smiling_face:

Sure thing!
First off, the player will enter in their ID into a textbox with the following code:
local Player = game.Players.LocalPlayer
local MPS = game:GetService(“MarketplaceService”)

script.Parent.MouseButton1Click:Connect(function()
	if tonumber(script.Parent.Parent.AudioID.Text) ~= nil then
		local AssetInfo = MPS:GetProductInfo(tonumber(script.Parent.Parent.AudioID.Text),Enum.InfoType.Asset)
		if AssetInfo.AssetTypeId == 3 then
			MPS:PromptProductPurchase(Player,990650466)
			game.ReplicatedStorage.Remotes.RE:FireServer(tonumber(script.Parent.Parent.AudioID.Text),"AudioPurchaseKey")
			
		else
			script.Parent.Parent.AudioID.Text = "Incorrect Audio File"	
		end
		
	else
			script.Parent.Parent.AudioID.Text = "Incorrect Format"
	end
end)

Next, If accepted, it fires a remote event over to the server, which processes the receipt:

local MPS = game:GetService("MarketplaceService")
local Datastore = game:GetService("DataStoreService")

local UserDatastore = Datastore:GetDataStore("ReciptInfo")

local ID 

game.ReplicatedStorage.Remotes.RE.OnServerEvent:Connect(function(plr,Audio,Key)
	if Key == "AudioPurchaseKey" then 
		ID = Audio
		return ID
	end
end)

MPS.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == 990650466 then 
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        
		game.ReplicatedStorage.Remotes.RE:FireAllClients("AudioTransfer",ID)
        return Enum.ProductPurchaseDecision.PurchaseGranted
       end

This then transfers the audio given back to the client, which contains the audio visualizer script as shown above :slight_smile: (Ill be going to be dnow, reading replies in the morning)