I have done some tweaking to your variables.
First why did I add events?
Well, I did that so it could wait till the player and character join instead of automatically getting it (If we were to automatically get it, and the player or character didn't add, it would return nil).
By the way, connect is deprecated, use Connect
I stored the sounds inside a table so you could easily access it.
I also didn't find the variable, oldHealth very useful since the argument in the HealthChanged event is the amount of health they have.
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local sounds = {
workspace.LowHealth,
workspace.CriticalHealth
}
humanoid.HealthChanged:Connect(function(health)
if health <= 30 then
sounds[1]:Stop()
sounds[2]:Play()
elseif health >= 30 then
sounds[2]:Stop()
sounds[1]:Play()
end
end)
If this answer fixed your problem, please accept it, if not, please ask questions
Please use the code block(the Lua button), and put your code inside(and please indent), it makes things readable
3 comments
codeblock pls
Ok. You know how to use hashtags to make headings, but not already codeblocks?
Do not only post code, or only post an explanation. Both are required to make a good question.