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