Currently stuck with a system I’m making. I’m trying to make a background music system that looks like it’s coming from speakers (but it’s just really coming from a part inside the speaker model). It randomly picks a song and each speaker plays it at the same time. It gets the ID that is chosen from a NumbeValue and sets the soundID to whatever the NumberValue is set to.
My Error:
( I know for a fact all of these ID’s are still available and public to use on the audio library, since I’ve tested them all )
My Scripts: Handler:
local MusicData = {9038476333,1839945406,1838667039,1838091800,1839945272,1846627694,1841241297}
while wait() do
wait(1)
local newSound = MusicData[math.random(1,#MusicData)]
val.Value = newSound
wait(1)
wait((script.DecidingSound.TimeLength)-1)
end
Script inside the part:
while wait() do
script.Parent.Sound:Stop()
if not script.Parent.Sound.IsPlaying then
local id = tostring(game.ServerScriptService.MusicDecider.Value.Value)
script.Parent.Sound.SoundId = id
script.Parent.Sound:Play()
wait(1)
wait((game.ServerScriptService.MusicDecider.DecidingSound.TimeLength)-1)
end
end
I fixed it (partially). It’s playing now, but only for about a second and then it switches songs.
No errors in the dev console.
Updated scripts:
Inside the part:
while wait() do
script.Parent.Sound:Stop()
if not script.Parent.Sound.IsPlaying then
wait(1.5)
local id = "rbxassetid://"..tostring(game.ServerScriptService.MusicDecider.Value.Value)
script.Parent.Sound.SoundId = id
script.Parent.Sound:Play()
wait(1)
wait(game.ServerScriptService.MusicDecider.DecidingSound.TimeLength)
end
end
Handler:
local val = script.Value
local MusicData = {9038476333,1839945406,1838667039,1838091800,1839945272,1846627694,1841241297}
while wait() do
local newSound = MusicData[math.random(1,#MusicData)]
val.Value = newSound
wait(1)
wait(script.DecidingSound.TimeLength)
end