I have three "speakers" that need a sound added to them. So I made a subroutine that adds the sound from a Table but it stopped working as soon as I added the WaitTime variable and only one "speaker" gets a sound. How can I make all my "speakers" get sounds? I'm doing it this way because I need this to work universally for different speakers. P.S I know I'm not calling the function in this code.
function AddSounds(Object, Sound)
if Object:IsA("Part") then
if Object.Name == "Speaker" then
local S = Sound:Clone()
S.Parent = Object
WaitTime = S.TimeLength
S:Play()
wait(WaitTime)
S:Destroy()
SoundAdded = false
print("Ready to play")
end
end
for _, child in ipairs(Object:GetChildren()) do
AddSounds(child, Sound)
end
end

2 comments
Most well explained coroutine I've ever seen on this site. Thanks mate.
I'd recommend using "coroutine.wrap" instead; it's similar to "coroutine.create" & "resume," but w/o the long typing, +, imo, it's simpler to use. Even better, I highly recommend using "spawn" over using the "coroutine"s, as it is much, much simpler to use, and gets the job done.