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

Help with Sound?

Asked by
iLegitus 130
9 years ago
function PlayInGameMusic()
    for i,v in pairs(game.Players:GetPlayers()) do 
        pcall(function() 
        if v.PlayerGui:FindFirstChild("LobbyMusic") then
            v.PlayerGui.LobbyMusic.Volume = 0
            local sound = Instance.new("Sound")
            sound.Name = "InGameMusic"
            sound.SoundId = "http://www.roblox.com/asset/?id=151011272"
            sound.Parent = v.PlayerGui
            sound.Volume = 0.8
            sound.Pitch = 1
            sound.Looped = true
            sound:Play()
        else

        end
        end)
    end
end

It works in play solo mode,But in multiplayer the "Lobby Music" keeps playing,Anyone help?

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

I don't know why it wouldn't be turning off.. perhaps you could try to just turn off ALL music in the player's playergui - just to be sure?

And I don't know why you used pcall, or put a blank else statement in your code..

function PlayInGameMusic()
    for i,v in pairs(game.Players:GetPlayers()) do 
        for a,b in pairs(v.PlayerGui:GetChildren()) do
            if b:IsA('Sound') then b:Destroy() end
        end
    end
    local sound = Instance.new("Sound",v.PlayerGui)
    sound.Name = "InGameMusic"
    sound.SoundId = "http://www.roblox.com/asset/?id=151011272"
    sound.Volume = 0.8
    sound.Pitch = 1
    sound.Looped = true
    sound:Play()
end
Ad

Answer this question