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

Songs start randomly playing when player resets?

Asked by 4 years ago

I made a script to play music. Problem is, whenever the player resets, another song starts playing in addition to the old one. My LocalScript in StarterGui:

SoundFolder = game.Workspace.SoundFolder

local Songs = SoundFolder.BGM:GetChildren()

print (Songs)

local CurrentSong = Songs[math.random(1,#Songs)]

print (CurrentSong)

local SongLength = CurrentSong.TimeLength

CurrentSong:Play()
SoundFolder.Wind:Stop()

game.ReplicatedStorage.Status.Changed:Connect(function(newstring)
    if newstring == "Game in progress." then
        for i, song in pairs(Songs) do
            song:Stop()
        end
        SoundFolder.Wind:Play()
        SoundFolder.Warning:Play()
    elseif newstring == "The game has ended! Initializing cleanup." then
        for i, song in pairs(Songs) do
            song:Stop()
        end
        CurrentSong = Songs[math.random(1,#Songs)]
        CurrentSong:Play()
        SoundFolder.Wind:Stop()
        SoundFolder.Warning:Stop()
    elseif newstring == "Waiting for players." then
        for i, song in pairs(Songs) do
            song:Stop()
        end
        CurrentSong = Songs[math.random(1,#Songs)]
        CurrentSong:Play()
        SoundFolder.Wind:Stop()
        SoundFolder.Warning:Stop()
    end
end)
0
You probably have the PlayOnRemove property ticked on the Sound. Azarth 3141 — 4y
0
No, it is off. NickIsANuke 217 — 4y

Answer this question