Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with Sound?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.