#Muting sounds associated with Player to others

1 messages · Page 1 of 1 (latest)

quiet lily
#

Hello! So I have this localscript in startscharacterscripts that is to mute any sound associated with the player such as running, jumping, swimming, etc (in a 6 second fade out effect, not that it matters but js fyi). The script does work but only for the client so that means others can still hear footsteps from that player and the player who has this function activated can still hear footsteps/sounds from other players (but themselves ofc). I have no idea how to make this mute other players aswell so i may need a little help.... 😓😓😓

#

First half of Script: ```lua
local Character = script.Parent

local Humanoid = Character:WaitForChild("Humanoid")

local Sound = Character.HumanoidRootPart.Running
local Sound2 = Character.HumanoidRootPart.Jumping
local Sound3 = Character.HumanoidRootPart.Climbing
local Sound4 = Character.HumanoidRootPart.Died
local Sound5 = Character.HumanoidRootPart.FreeFalling
local Sound6 = Character.HumanoidRootPart.GettingUp
local Sound7 = Character.HumanoidRootPart.Landing
local Sound8 = Character.HumanoidRootPart.Splash
local Sound9 = Character.HumanoidRootPart.Swimming``` then other half is just using tweenservice to mute these sounds such as this for example ```lua

local DefaultVol2 = 0.65
local Properties2 = {Volume = DefaultVol2 - 0.65}
local Info2 = TweenInfo.new(6, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local T2 = game:GetService("TweenService"):Create(Sound2, Info2, Properties2)
T2:Play()```

gilded crown
#

Sorry if I misunderstood, but I think you're trying to make it so that all players won't be able to hear sounds coming from a specific player, right? If so, you can create a server script that fires the event to all clients with the target player included. Then, in a LocalScript inside StarterPlayerScripts, you can listen for the remote event and mute the sounds using a tween. It would work something like this:

#

server script inside ServerScriptService:local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local MuteEvent = ReplicatedStorage:WaitForChild("MuteCharacterSounds")

wait(3)

local firstPlayer = Players:GetPlayers()[1]
if firstPlayer then
MuteEvent:FireAllClients(firstPlayer)
end

#

local script inside StarterPlayerScripts:local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local MuteEvent = ReplicatedStorage:WaitForChild("MuteCharacterSounds")

local function muteCharacterSounds(character)
local root = character:FindFirstChild("HumanoidRootPart")
if not root then return end

local soundNames = {
    "Running",
    "Jumping",
    "Climbing",
    "Died",
    "FreeFalling",
    "GettingUp",
    "Landing",
    "Splash",
    "Swimming",
}

for _, soundName in ipairs(soundNames) do
    for _, descendant in ipairs(root:GetDescendants()) do
        if descendant:IsA("Sound") and descendant.Name == soundName then
            local sound = descendant
            task.spawn(function()
                local startVolume = sound.Volume
                local duration = 6
                local startTime = tick()
                while tick() - startTime < duration do
                    local elapsed = tick() - startTime
                    local alpha = elapsed / duration
                    sound.Volume = startVolume * (1 - alpha)
                    task.wait()
                end
                sound.Volume = 0
            end)
        end
    end
end

end

MuteEvent.OnClientEvent:Connect(function(targetPlayer)
local character = targetPlayer.Character
if character then
muteCharacterSounds(character)
else
targetPlayer.CharacterAdded:Wait()
muteCharacterSounds(targetPlayer.Character)
end
end)

gilded crown
#

and if i misunderstood and you meant a single script without remote events.. just loop through all the players? 🫡 local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

local function muteCharacterSounds(character)
local root = character:FindFirstChild("HumanoidRootPart")
if not root then return end
local soundNames = {
"Running",
"Jumping",
"Climbing",
"Died",
"FreeFalling",
"GettingUp",
"Landing",
"Splash",
"Swimming",
}

for _, soundName in ipairs(soundNames) do
    for _, descendant in ipairs(root:GetDescendants()) do
        if descendant:IsA("Sound") and descendant.Name == soundName then
            local sound = descendant
            local tweenInfo = TweenInfo.new(
                6, --duration in seconds ofc
                Enum.EasingStyle.Linear,
                Enum.EasingDirection.Out
            )

            local goal = { Volume = 0 }
            local tween = TweenService:Create(sound, tweenInfo, goal)
            tween:Play()
        end
    end
end

end

task.wait(3)

for _, player in ipairs(Players:GetPlayers()) do
if player.Character then
muteCharacterSounds(player.Character)
player.CharacterAdded:Connect(function(newCharacter)
muteCharacterSounds(newCharacter)
end)
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
muteCharacterSounds(character)
end)
end)

terse dome