Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I play music with a loop on, without it interrupting on serverside?

Asked by 3 years ago
1local Sound2 = Instance.new("Sound", Character)
2Sound2.SoundId = "rbxassetid://4825612647"
3Sound2.Volume = 1
4Sound2.Looped = true
5Sound2:Play()
6 
7while wait() do
8    game:GetService("SoundService"):PlayLocalSound(Sound2) -- I realized this was clientside, and now I'm in a hole where I don't know what to do.
9end
0
Do you just want to do it localy to players? spectsy 16 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You're actually playing the sound twice.

1local Sound2 = Instance.new("Sound", Character)
2Sound2.SoundId = "rbxassetid://4825612647"
3Sound2.Volume = 1
4Sound2.Looped = true
5Sound2:Play() -- here...
6 
7while wait() do
8    game:GetService("SoundService"):PlayLocalSound(Sound2) -- ...and right here
9end

The server plays the sound to all clients (I'm assuming it does, but if it doesn't then you should parent the Sound to anything the client can access, like ReplicatedStorage) and you're playing it locally...again. If you're trying to play it on one client, why not try playing the sound from a LocalScript?

I also would not suggest looping the sound, because that's likely the reason it's interrupting itself. Every time the loop iterates, it plays the sound from the beginning over and over again. At best, play the sound and wait for it to finish in a loop:

1while true do
2    Sound2:Play()
3    -- There are two different ways you can do this. One is by directly polling for the sound to finish by using another loop. The other is to use the script signal. (Both of them poll for it anyway.) I will demonstrate both of these options.
4    -- Option 1
5    repeat wait() until not Sound2.IsPlaying
6    -- Option 2
7    Sound2.Ended:Wait()
8end
Ad

Answer this question