My goal is to make a function that loops through a part holding all swoosh sounds for a sword, then it plays any of the 3 sounds that “IsPlaying == false”.
My code:
local function swoosh()
for _, sound in pairs(weapon.SwooshSounds:GetChildren()) do
if sound.IsPlaying == false then
sound:Play()
end
end
end
There’s 3 audios in the part and the main issue is it works somewhat but it only will see the first audio not the other two in the part.
local children = weapon.SwooshSounds:GetChildren()
local sounds = {}
local playing = {}
for i, v in pairs(children) do
if v:IsA("Audio") then
table.insert(sounds, v)
end
end
local function play()
local n = math.random(1,#sounds)
local sound = sounds[n]
sound:Play()
table.remove(sounds, n)
table.insert(playing, sound)
coroutine.wrap(function()
sound.Ended:Wait()
table.insert(sounds, sound)
table.remove(playing, table.find(playing, sound))
end)
end