Trying to make a music system via speakers - Getting stuck on an error

Hey developers!

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:
image

( 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

Any help is appreciated.

Thanks!

Have you tried publishing your own sound and play it using your script?

No. Let me try that. I’m ID verified so that shouldn’t be an issue with mass uploads.

1 Like

Didn’t work. Getting the same error. The audio I used has been up for months, so it isn’t an issue related to it not being approved yet.
image

try rewriting this line to this:

local id = rbxassetid://..tostring(game.ServerScriptService.MusicDecider.Value.Value)

image

why is the id behind // “0” ? there should be the idCode

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

because you stop the sound before checking if its playing, which always results in playing the new song

Ah yes! Thank you! Obvious mistake on my end. Thank you for your help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.