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
11 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.

01while wait() do
02local song=math.random(1,5);
03        if song==1 then
04            game.Workspace.Feeling:Play()
05            wait(120)
06            game.Workspace.Feeling:Stop()
07        elseif song==2 then
08            game.Workspace.Po:play()
09            wait(120)
10            game.Workspace.Po:Stop()
11       elseif song==3 then
12            game.Workspace.Demons:play()
13            wait(120)
14            game.Workspace.Demons:Stop()
15elseif song==4 then
View all 24 lines...

I have also tried this:

01function startSong()
02    local isStarted1 = false
03    local isStarted2 = false
04    while true do
05        if not isStarted1 then
06            game.Workspace.song1name:Play()
07            isStarted1 = true
08            wait(song1length)
09            game.Workspace.song1name:Stop()
10            isStarted1 = false
11        elseif not isStarted 2 then
12            game.Workspace.song1name:play()
13            isStarted2 = true
14            wait(song2length)
15            game.Workspace.song2name:Stop()
View all 21 lines...
0
Is this inside the StarterGui? If not, I don't see why it's keeps playing music when more people join. Thewsomeguy 448 — 11y
0
Post the entire script. Bebee2 195 — 11y
0
Those are the ENTIRE Scripts. Scenal 20 — 11y
0
And yes, it is in the StarterGUI. Scenal 20 — 11y
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 — 11y
0
Its for all players. But I'm trying to make it so that all the players universally here ONE tune together. Scenal 20 — 11y

2 answers

Log in to vote
1
Answered by 11 years ago

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

02local songs = {"151132026","153519026","147255650","142993375","142833359"}
03local audio = Instance.new("Sound", workspace)
04audio.Looped = false
05audio.Volume = 1
06function playMusic()
07audio.SoundId = baseurl .. songs[math.random(1, #songs)]
08audio:Play()
09wait(120)
10audio:Stop()
11playMusic()
12end
13playMusic()

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:

01local baseurl = "rbxasset://"
02local songs = {"sounds/victory.wav", "sounds/electronicpingshort.wav"}
03local audio = Instance.new("Sound", workspace)
04audio.Looped = false
05audio.Volume = 1
06function playMusic()
07audio.SoundId = baseurl .. songs[math.random(1, #songs)]
08audio:Play()
09wait(1)
10audio:Stop()
11playMusic()
12end
13playMusic()
Ad
Log in to vote
1
Answered by 11 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