How to mute other player's sounds

I was swimming around with my friend in my water game, but I can hear him swim too. How do I disable being able to hear him swim while still being able to hear myself swim? I’m referring to the HumanoidRootPart.Swimming sound.

2 Likes

Put this in a LocalScript in StarterPlayerScripts

local Players = game:GetService'Players'
local LocalPlayer = Players.LocalPlayer

local function OnCharacter(Character)
	local Sound = Character:WaitForChild'HumanoidRootPart':WaitForChild'Swimming'
	Sound.Volume = 0
end

local function OnPlayer(Player)
	if Player ~= LocalPlayer then
		if Player.Character then
			OnCharacter(Player.Character)
		end
		Player.CharacterAdded:Connect(OnCharacter)
	end
end

for i, Player in pairs(Players:GetPlayers()) do
	OnPlayer(Player)
end

Players.PlayerAdded:Connect(OnPlayer)

Whoops, accidentally marked it as the solution.

PlayerAdded doesn’t work in local scripts. Also only the local player has the Swimming sound on them.

PlayerAdded does work in local scripts you should test it out and see

Well I don’t know if you already fixed this, but his script had a typo in it. Try fixing that and see if it works.

Should be:

local Players = game:GetService('Players')

I just did game.Players instead of doing game:GetService(‘Players’). Do I actually have to import the service for it to work?

No you don’t. Were there any errors in the output? That script should work fine. Maybe try adding prints to see if it actually runs the functions OnCharacter and OnPlayer.

I’ll try that. It didn’t work or produce any errors, I tried adding a print to see when a player is added but it never printed for some reason. Does it print when it’s only me, or do I have to have my friend join me to see if it prints with him?

You need to have a friend join. You join before the local script runs, so it won’t count you in the Player Added Event. Though it should run because of this code:

for i, Player in pairs(Players:GetPlayers()) do
	OnPlayer(Player)
end

Where did you put the print?

I did not put that code, I didn’t copy it exactly; I just did the PlayerAdded thing.

That’s what I get for thinking I’m smart haha, I’ll put your code exactly and get back to you with an update. Sorry about that, should have made it clear.

Any players that were there before you joined wouldn’t be muted from the Player Added event, so that it loops through all of the players and mutes them.

Alright it works! Thanks for all the help guys! I’m going to mark the post with the code the solution, but you were a big help too! :slight_smile: Thank you!

1 Like

that’s not a typo ‘Players’ and (‘Players’) works the same way