Sound running globally on LocalScript (ZonePlus)

I have areas where different ambients should play, although even though :Play() is called on a LocalScript, other players can also hear the sound. How should I stop this?

local ZoneModule = require(game:GetService("ReplicatedStorage").Modules.Zone)

for _, zone in pairs(workspace.World.EarthMap.MusicZones:GetChildren()) do
	local Sound = Instance.new("Sound")
	Sound.Parent = script.Sounds
	Sound.Looped = true
	Sound.Name = zone.Name
	local MusicZone = ZoneModule.new(zone)
	local MusicID = zone:GetAttribute("MusicID")
	local MusicVolume = zone:GetAttribute("MusicVol")
	Sound.SoundId = string.format("rbxassetid://%s",MusicID)
	Sound.Volume = MusicVolume
	MusicZone.playerEntered:Connect(function()
		Sound:Play()
	end)
	MusicZone.playerExited:Connect(function()
		fadeOut(Sound)
		Sound:Stop()
	end)
end
function fadeOut(Sound)
	local SoundVol = Sound.Volume
	repeat
		Sound.Volume -= 0.1
		game:GetService("RunService").Heartbeat:Wait()
	until
	Sound.Volume == 0
	Sound.Volume = SoundVol
end
1 Like

If it isn’t already, set RespectFilteringEnabled to true in SoundService

I believe you are not respecting the player bounds

MusicZone.playerEntered:Connect(function()
		Sound:Play()
	end)

for all clients, this will fire whenever any player enters the zone

to fix this, utilize the player parameter that goes along with this function

local Player = game.Players.LocalPlayer
MusicZone.playerEntered:Connect(function(player)
		if player.Name==Player.Name then
           Sound:Play()
        end

	end)

Apply this method to all you sound changing stuff and this should fix your issue

3 Likes

Wow! That fixed my issue! It’s unclear to me why this happens but, if it works, it works.

it is not unclear this single line explains:

for all clients, this will fire whenever any player enters the zone

1 Like