I have a script where it’ll make music play from multiple parts with the same name. The issue is it only works on 1/4 parts, and it’s a different part each time. Here’s my script:
local MusicData = {1836009584,1841274055}
for i,v in pairs(workspace.speakers:GetChildren()) do
if v.Name == "Speaker" then
local s = v.MusicPart.Sound
s:Stop()
if not s.IsPlaying then
local newSound = MusicData[math.random(1,#MusicData)]
s.SoundId = 'rbxassetid://'..newSound
s:Play()
wait(1)
wait((s.TimeLength)-0.00001)
end
end
end
Now someone correct me if I’m wrong but what I believe is happening is that the “wait” is making the actual for do loop wait as well, maybe try putting the actual code into a spawn()
Like this
local MusicData = {1836009584,1841274055}
for i,v in pairs(workspace.speakers:GetChildren()) do
if v.Name == "Speaker" then
local s = v.MusicPart.Sound
s:Stop()
if not s.IsPlaying then
spawn(function()
local newSound = MusicData[math.random(1,#MusicData)]
s.SoundId = 'rbxassetid://'..newSound
s:Play()
wait(1)
wait((s.TimeLength)-0.00001)
end)
end
end
end
I know a spawn() might be unethical, but it’ll get the job done.