-
What do you want to achieve?
To mute sounds when you die and then restore the sound volumes back after respawning. -
What is the issue?
The script doesnt restores the sound volumes! -
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()
