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
    local Sound2 = Instance.new("Sound", Character)
    Sound2.SoundId = "rbxassetid://4825612647"
    Sound2.Volume = 1
    Sound2.Looped = true
    Sound2:Play()

    while wait() do
        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.
    end
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.

local Sound2 = Instance.new("Sound", Character)
Sound2.SoundId = "rbxassetid://4825612647"
Sound2.Volume = 1
Sound2.Looped = true
Sound2:Play() -- here...

while wait() do
    game:GetService("SoundService"):PlayLocalSound(Sound2) -- ...and right here
end

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:

while true do
    Sound2:Play()
    -- 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.
    -- Option 1
    repeat wait() until not Sound2.IsPlaying
    -- Option 2
    Sound2.Ended:Wait()
end
Ad

Answer this question