Hello! I’m basically just trying to do what the title says. I’m trying to get my heartbeat audio to match the humanoid’s health property. Here is my current code, that doesn’t seem to work.
local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local sound = player.PlayerGui.HurtOverlay.Heartbeat
while true do
wait()
sound.Volume = humanoid.Health / 100
end
I thought I had playing on, but I guess I didn’t. That fixed it, but now the audio volume is high when the health is high instead of when the health is low.
That worked too! Now I’m wondering, is there any way to keep the volume equal to or less than 10 so the volume isn’t too much? I know I’m asking for a lot but I was just curious if there was a way somehow.
it’ll return a volume of 0-1, however if you define a max volume variable, you can multiply that entire formula by said variable to get it to be 0 to whatever volume you desire
local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local sound = player.PlayerGui.HurtOverlay.Heartbeat
local heartBeatVolume = 2 -- can make this any number really
while true do
wait()
sound.Volume = ((humanoid.MaxHealth-humanoid.Health)/humanoid.MaxHealth)*heartBeatVolume
end
local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local sound = player.PlayerGui.HurtOverlay.Heartbeat
local soundVolume = 0.1 -- can make this any number really
humanoid.HealthChanged:Connect(function()
wait()
sound.Volume = ((humanoid.MaxHealth-humanoid.Health)/humanoid.MaxHealth)*soundVolume
end)
But now no audio is playing, or at least the volume isn’t working.
i see you used humanoid.HealthChanged, are you changing the health to test the volume or just running it without setting anything? try printing in the function to see if it runs and print the sound volume to see if it alters or not
I was trying what someone else suggested, but even when trying both while true do and humanoid.HealthChanged:Connect(function() it doesn’t even print anything. Is it because I’m using a LocalScript?