Refreshing HUDPaint hook

Sort of a quick question, I have this quick function to draw the health above a given entity:

The health is drawn however, the value for the health does not refresh and the text above the entity always stays at the initial value of the entity health.

Is there any way to refresh this value and make the health above the head print in realtime?
Thanks in advance

Why are you checking if it is func_tracktrain when you’re CLEARLY looping through a table that ONLY contains func_tracktrain?
Also, you should do some research and attempt to LEARN the language, not just copypaste some functions. HUDPaint ALWAYS updates except for when the console is open, your entities health is the part that isn’t updating.
ADDITIONALLY, .toscreen is not part of the function you’re trying to get it out of.

I was changing around this function a good bit, I left in a redundancy that checked for func_tracktrain twice. whoops.

I initially thought that the hudpaint hook didn’t call more than once, but it was the variables that weren’t being networked to the client that made me believe that it wasn’t being called more than once.

The entities health was updating fine, the variables weren’t being networked to the client correctly. I fixed this using ent:GetDTInt(0) with some help from .\Shadow}

You have no idea what you’re talking about. What you initially tried and what you just described were two COMPLETELY different things

well, I used the same function to draw the text, but I had to set the health inside the entity using ent:SetDTInt(0) because using the method ent.Health() wouldn’t network the health properly to the client.

It was my mistake to think that the problem was HUDPaint hook not calling more than once and not the variable being networked to the client properly, but I got it all now.

You’re completely missing the point.