So let me tell you what I want: I have 29 sound objects in my game which contain different voices for different situations. In order to prevent them from being played at the same time, I am trying to make a queue script. So if a voice is playing, and another voice wants to be played too, it should be queued in a table.
local SoundRemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("Voice")
local SoundBindableEvent = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("MainGui"):WaitForChild("Frames"):WaitForChild("Events"):WaitForChild("Voice")
local Folder = script.Parent
local Queue = {}
function PlayVoice(Number)
for i,v in pairs(Folder:GetChildren()) do
if v:IsA("Sound") then
if v.IsPlaying == true then
table.insert(Queue, #Queue + 1, Folder:WaitForChild(tostring(Number)))
repeat wait() until v.IsPlaying == false
local A = Queue[1]
table.remove(Queue, 1)
A:Play()
break
else
Folder:WaitForChild(tostring(Number)):Play()
break
end
end
end
end
SoundRemoteEvent.OnClientEvent:Connect(PlayVoice)
SoundBindableEvent.Event:Connect(PlayVoice)
Sounds still play at the same time…
Anyone see what I did wrong?