How to restore back sound volumes after death?

  1. What do you want to achieve?
    To mute sounds when you die and then restore the sound volumes back after respawning.
  2. What is the issue?
    The script doesnt restores the sound volumes!
  3. What solutions have you tried so far?
    Yes, i did search for solution on dev forum, it seems like nobody had this problem like mine.

This is the script that is located in StarterCharacterScripts, it supposed to restore volumes of sounds after respawning, doesnt works.

task.wait(1.5)
local TweenService = game:GetService("TweenService")
local RunService = game:GetService('RunService')
local UserInputService = game:GetService("UserInputService")
local storage = game.ReplicatedStorage.Strg
local hitboxModule = require(storage.Modules:WaitForChild("RaycastHitboxV4"))

local plr = game.Players.LocalPlayer
local PlayerName = plr.Name
local char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = char:WaitForChild('Humanoid')
local HumanoidRootPart = char:WaitForChild('HumanoidRootPart')
local Torso = char:WaitForChild('Torso')
local head = char:WaitForChild("Head")
local deathGui = plr.PlayerGui.Death
local sprintPlaying = false
local cooldown = false
local audioClips = storage.Sounds.FleshImpacts:GetChildren()
local SprintAnim = char.Animate.run.RunAnim
local sprint = Humanoid:LoadAnimation(SprintAnim)
local originalVolumes = {}
local SoundService = game.SoundService
local PlayerProfile = storage.Misc.PlayerProfiles:FindFirstChild(PlayerName)
-- Original CFrame values
local RootJointOriginalC0 = HumanoidRootPart.RootJoint.C0
local NeckOriginalC0 = Torso.Neck.C0
local RightHipOriginalC0 = Torso['Right Hip'].C0
local LeftHipOriginalC0 = Torso['Left Hip'].C0

-- Movement and animation variables
local RangeOfMotion = math.rad(45)
local RangeOfMotionTorso = math.rad(45)
local RangeOfMotionXZ = RangeOfMotion / 140
local LerpSpeed = 0.005
local moveVelocity = Vector3.new()
local moveAcceleration = 6
local PlayersTable = {}
local existingAttachment = char["Right Leg"]:FindFirstChild("HitboxAttachment")

local function restoreVolumes()
	for sound, originalVolume in pairs(originalVolumes) do
		if sound:IsA("Sound") and PlayerProfile.Values.Effects.Value then
			sound.Volume = PlayerProfile.Values.Effects.Value
		end
	end
end
	whiteGui.BackgroundTransparency = 0
	game.SoundService.AmbientReverb = Enum.ReverbType.UnderWater
	local whiteTween = TweenService:Create(whiteGui, TweenInfo.new(0.4, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {BackgroundTransparency = 1})
	whiteTween:Play()
	deathGui.CinematicBoom:Play()
	local workspaceSounds = workspace
	local effects = {}
	for _, sound in ipairs(workspaceSounds:GetChildren()) do
		if sound:IsA("Sound") then
			if not originalVolumes[sound] then
				originalVolumes[sound] = sound.Volume
			end
			if sound.Name == "CinematicBoom" or sound.Name == "Flatline" then
				sound.Volume = 1
			else
				sound.Volume = 0
			end
			table.insert(effects, {Name = sound.Name, Volume = originalVolumes[sound]})
		end
	end
	char.Dat.StoreEffects:FireServer(effects)
	task.wait(0.55)
	deathGui.Flatline:Play()
	TweenService:Create(deathGui.Flatline, TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Volume = 0}):Play()
end)

restoreVolumes()
1 Like

are there any errors in console when you run the code?

Nope, there’s no errors, it just doesnt restores them back.

have you tried adding a print() statement to the restoreVolumes function to see when its being ran? I can only assume I’m not seeing the entire script due to the seam here (note the indent)

I have noticed that you have an end) that errors the script at the end of the code and whiteGui is not a stored variable, they might be the problem.