Trying to make volume of music tween back and forth when you die

I’m trying to make it so that if the player dies, the music playing tweens to zero volume, and back to 1 volume.

But then it just does nothing when I die.

local players = game:GetService('Players')
local plr = players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild('Humanoid')
local ts= game:GetService('TweenService')
local info = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false)
local goal = {Volume = 0}
local goal2 = {Volume = 1}
local sound1 = script.Sound1
local sound2 = script.Sound2
game.ReplicatedStorage.Sounds.SoundEvent1.OnClientEvent:Connect(function()
	sound1.Playing = false
	sound2.Playing = true
end)
humanoid.Died:Connect(function()
	local soundtween = ts:Create(sound1,info,goal)
	soundtween:Play()
	task.wait(3)
	local soundtween2 = ts:Create(sound1,info,goal2)
	soundtween2:Play()
end)
game.ReplicatedStorage.Sounds.SoundEvent2.OnClientEvent:Connect(function() --- dont mind this part, I didnt add the tween yet.
	sound1.Playing = true
	sound2.Playing = false
	humanoid.Died:Connect(function()
		sound1.Playing = false
		task.wait(3)
		sound1.Playing = true
	end)
end)
I don't know what went wrong with it.
1 Like

Where is the script located?
Is this a local or server script?
Have you tried putting prints in each of the functions to see if they are firing?
Is Volume = 1 loud enough to play the sounds?
Why not try loading the sounds in the script, then just playing them instead of tracking back to ReplicatedStorage?

You also have 2 humanoid.Died:Connect functions with sounds in them.

1 Like

I changed it so instead of a tween its just a for loop, but now when I die, the music comes back in a lower pitch than usual.

local players = game:GetService('Players')
local plr = players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild('Humanoid')
local sound1 = game.SoundService.Sound1
local isplaying1 = true
local sound2 = game.SoundService.Sound2
game.ReplicatedStorage.Sounds.SoundEvent1.OnClientEvent:Connect(function()
	sound1.Playing = false
	sound2.Playing = true
	local isplaying = true
	print("STEP1")
end)
game.ReplicatedStorage.Sounds.SoundEvent2.OnClientEvent:Connect(function()
	sound1.Playing = true
	isplaying1 = false
	sound2.Playing = false
end)
humanoid.Died:Connect(function()
	print("STEP2")
	if isplaying1 == true then
		for i = 1,10 do
			wait(0.05)
			sound2.PlaybackSpeed = sound2.PlaybackSpeed - 0.1
		end
		print("step3")
		wait(2)
		for i = 1,10 do
			wait(0.05)
			sound2.PlaybackSpeed = sound2.PlaybackSpeed + 0.1
		end
		print("step4")
	end
	if isplaying1 == false then
	sound1.PlaybackSpeed = 0
	task.wait(3)
	sound1.PlaybackSpeed = 1
	end
end) -- In startercharacter scripts/local script