Hello, I have this code that its supposed to check if a sound its playing and if so clone and send a part to its position, however not only does it not iterate thru the entire table at the same time I also don’t know how to make it not stop the loop
while task.wait() do
for _, sound in soundList do
for _, part in Folder:GetChildren() do
if part.Name == sound.Name then
return
elseif part.Name ~= sound.Name then
part:Destroy()
end
end
local clone = soundIndicator:Clone()
clone.Parent = Folder
clone.Name = sound.Name
clone.Position = sound.Parent.Position
end
end
Here’s the entire code for context:
--// GameServices
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//
local soundScanner = task.spawn(function()
--// Paths
local Mechanics = ReplicatedStorage:WaitForChild('Mechanics')
local soundIndicator = Mechanics:WaitForChild('SoundBubble')
local Folder = workspace:WaitForChild('SoundIndicators')
--//
--// Values
local soundList = {}
--//
task.spawn(function()
while task.wait() do
for _, sound in workspace:GetDescendants() do
if sound:IsA('Sound') then
if sound.Playing == true then
if not table.find(soundList, sound) then
table.insert(soundList, sound)
end
end
end
end
end
end)
task.spawn(function()
while task.wait() do
for _, sound in workspace:GetDescendants() do
if sound:IsA('Sound') then
if sound.Playing == false then
if table.find(soundList, sound) then
table.remove(soundList, table.find(soundList, sound))
end
end
end
end
end
end)
task.spawn(function()
while task.wait() do
for _, sound in soundList do
for _, part in Folder:GetChildren() do
if part.Name == sound.Name then
return
elseif part.Name ~= sound.Name then
part:Destroy()
end
end
local clone = soundIndicator:Clone()
clone.Parent = Folder
clone.Name = sound.Name
clone.Position = sound.Parent.Position
end
end
end)
task.spawn(function()
while task.wait(1) do
print(soundList)
end
end)
end)
--//