HUD Low HP Sound Warning


I want to make something for my HUD that makes a sound every 5 sound when my HP is below 10.
I tried using some timer tricks, and played around surface.PlaySound(“path”) but it doesnt works.

How can I do?

timer.Create(“LowHealth”, 5, 0, function()
if LocalPlayer():Health() < 10 then
Didn’t test it, but something like this should work.

That’s exactly what I made, but it didn’t work.

Did you put the right sound path?
Did you make sure to actually install the sound?
(I know these are stupid tips but you never know)

Maybe your sound file wasn’t working? I’m not sure if mp3’s are working in GMod again yet.

That is what he asked for but that’s a terrible way of doing it if you want it to work properly, if you know what I mean.

if SERVER then
hook.Add(“EntityTakeDamage”, “CheckPlayerHealth”, function(ent, dmginfo)
if !dmginfo or !IsValid(ent) or !ent:IsPlayer() then return end

	if (ent:Health()-dmginfo:GetDamage()) &lt;= 9 then

net.Receive(“HPLowSound”, function(len)
local ply = LocalPlayer()
if !IsValid(ply) then return end
timer.Create(“HPLowSound_”…ply:EntIndex(), 5, 0, function()
if !IsValid(ply) or ply:Health() >= 10 then

I’m gonna try that brandonj, thank you if it works.

Can you just explain what is exactly EntityTakeDamage hook argument “dmginfo”?

It does work, or else I wouldn’t post it…

The “EntityTakeDamage” hook’s “dmginfo” argument is simply a class to hold what damage to be applied.

More info here:

It doesn’t work. I ran the code both serverside and clientside, it tried making my HP 19 and falling to 9 HP, it didn’t play the sound.

That’s too bad because it works for me.

This code should be in “lua/autorun/”

Should it be in a separate file from the hud or in the same file as HUD code?

That still didn’t work.

Show your code then.

I don’t know why you’re using luapad when Garry’s Mod has lua refresh.

It looks like you copy and pasted it inside your “if CLIENT then end” and you shouldn’t have to use luapad, just make GMod windowed.

I’m not using luapad, I use GCompute (I’m on a server) and the folder was here so I randomly saved it in.

Edit: Ok I edited stuff in the pastes.

Do a “print(“Playsound”)” on line 21 of the shared file because I know it does work, you can even use my original code.

What do you mean by “Do a “print(“Playsound”)” on line 21”? (Sorry if I’m extremely stupid)

Just replace that whole file with the code I posted so I know it’s not a sound error in which you should be checking your console for errors.