Tween volume depending on health

I’m trying to tween an audio volume to be quieter when health is slowly regenerating to full but louder when it’s decreasing, I figured it for image transparency since it goes from 1 to 0 but not sure about audio volume since it’s opposite.

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local GUI = Player:WaitForChild("PlayerGui").Main.ImageLabel
Humanoid.HealthChanged:Connect(function(Health)
	game:GetService("TweenService"):Create(GUI, TweenInfo.new(0.2), {ImageTransparency = Health/Humanoid.MaxHealth}):Play()
	game:GetService("TweenService"):Create(workspace.Sound, TweenInfo.new(0.2), {Volume = Health/Humanoid.MaxHealth}):Play() -- Which formula?

end)
1 Like

if you want it to be the opposite then do

Volume = (1 - Health/Humanoid.MaxHealth)*x --replace x with the factor

the factor above will determine the maximum volume.
if the health is 0 and the factor is 1 then the volume will be 1.
if the health is 0 and the factor is 2 the volume will be 2.
etc…
Hope this helped :grin:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.