I’m trying to make a health GUI (without a health bar) but the health isn’t updating. It changes the first time when I load in (default text to the health), but after that it doesn’t update.
I haven’t really tried anything because I’m not sure what to try, I’ve tried looking up tutorials but all I’ve seen is for a health BAR and not actual numbers.
I’ve searched other DevForum posts but none of them worked, either that or I couldn’t really understand them (i am quite new to scripting).
Any help would be appreciated.
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local GUI = script.Parent
local Health = GUI.Health
local HP = Humanoid.Health
while true do
wait(0)
Health.Text = HP
end
You’re only updating it to a preset amount of health in the HP variable, you’re not updating it with the curernt hp of the Humanoid
I would recommend using .HealthChanged, which is an event of the Humanoid to determine the health of the humanoid rather tahn a while loop which is unperformant
This is a really simple misconception I’ve seen a lot of people do (including myself)
You’re storing the Humanoid’s Health property in a variable, which works. However, that will not update in realtime by itself to the value of the Humanoid’s Health property, this is what’s known as passing by value. The value of Health is stored in the variable, if that makes sense. So if the current health is at 100, HP will store a number being 100.
To fix? Just read from the Health property in your loop directly. However, it might be more efficient to use a Changed event to update the text, like so:
I would recommend flooring the Health of the humanoid since it’s going to return extreme decimals due to Roblox’s health system multiplying a wait with the health regeneration, causing non whole numbers
If you disabled the default regen system, then I don’t think there’s any need, but better to safe than sorry of course. I would recommend using the code I made which does exactly as @C_Sharper does, but floors the Health incase it’s a decimal number and uses .HealthChanged which is like how he did with GetPropertyChangedSignal but with HealthChanged, it also returns the current health of the humanoid, meaning we don’t have to reference the Humanoid’s health property