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

Why does my music script keep playing music when more people join?

Asked by
Scenal 20
10 years ago

When other people join the game, the script plays music again and it overlaps the sounds, making it a pain to listen to.

while wait() do
local song=math.random(1,5);
        if song==1 then
            game.Workspace.Feeling:Play()
            wait(120)
            game.Workspace.Feeling:Stop()
        elseif song==2 then
            game.Workspace.Po:play()
            wait(120)
            game.Workspace.Po:Stop()
       elseif song==3 then
            game.Workspace.Demons:play()
            wait(120)
            game.Workspace.Demons:Stop()
elseif song==4 then
            game.Workspace.Trumpets:play()
            wait(45)
            game.Workspace.Trumpets:Stop()
elseif song==5 then
            game.Workspace.Survival:play()
            wait(100)
            game.Workspace.Survival:Stop()
        end
end

I have also tried this:

function startSong()
    local isStarted1 = false
    local isStarted2 = false
    while true do
        if not isStarted1 then
            game.Workspace.song1name:Play()
            isStarted1 = true
            wait(song1length)
            game.Workspace.song1name:Stop()
            isStarted1 = false
        elseif not isStarted 2 then
            game.Workspace.song1name:play()
            isStarted2 = true
            wait(song2length)
            game.Workspace.song2name:Stop()
            isStarted2 = false
        end
        wait(1) -- Wait 1 second before relooping again, or it will crash for StackOverflow (infinite loop)
    end
end
startSong()

0
Is this inside the StarterGui? If not, I don't see why it's keeps playing music when more people join. Thewsomeguy 448 — 10y
0
Post the entire script. Bebee2 195 — 10y
0
Those are the ENTIRE Scripts. Scenal 20 — 10y
0
And yes, it is in the StarterGUI. Scenal 20 — 10y
View all comments (2 more)
0
That's the reason why. Try moving it to workspace. Or are you trying to play it just for the player? Thewsomeguy 448 — 10y
0
Its for all players. But I'm trying to make it so that all the players universally here ONE tune together. Scenal 20 — 10y

2 answers

Log in to vote
1
Answered by 10 years ago

Try this, put the Script (not Localscript) in game.ServerScriptService:

local baseurl = "http://www.roblox.com/asset/?id="
local songs = {"151132026","153519026","147255650","142993375","142833359"}
local audio = Instance.new("Sound", workspace)
audio.Looped = false
audio.Volume = 1
function playMusic()
audio.SoundId = baseurl .. songs[math.random(1, #songs)]
audio:Play()
wait(120)
audio:Stop()
playMusic()
end
playMusic()

By the way, where it says local songs = {"151132026","153519026","147255650","142993375","142833359"}, you can add more Ids to that list at anytime, and it would still work.

UPDATE:

I heard you were still having issues. Try this and play solo. It's a simplified version with different sound. If it doesn't work, another script is messing up the sound:

local baseurl = "rbxasset://"
local songs = {"sounds/victory.wav", "sounds/electronicpingshort.wav"}
local audio = Instance.new("Sound", workspace)
audio.Looped = false
audio.Volume = 1
function playMusic()
audio.SoundId = baseurl .. songs[math.random(1, #songs)]
audio:Play()
wait(1)
audio:Stop()
playMusic()
end
playMusic()
Ad
Log in to vote
1
Answered by 10 years ago

The sound is in the Workspace which is actually the cause the problem. If you put the music at the Workspace then it's played in every place where you are. Because of that it is set to play music at the Workspace then the player joins the game then the sound gets mixed together and that makes the problem so instead of putting the sound at the Workspace then place it at the PlayerGui which causes it to only play music at the client without sound is coming from other players.

Answer this question