UI systems 5 min read

Build a Health HUD and a Notification Queue

Give players persistent health feedback and queue short notifications so messages stay readable.

Drive the bar from Humanoid values

Compute the ratio from Health and MaxHealth and clamp it from zero to one. Use the ratio for bar width, and interpolate the color between red and green. Listen to both values when updating. Disconnect previous listeners and bind to the new Humanoid after a character reset.

Queue fast messages

Give a ModuleScript one TextLabel to manage. Push notifications into a bounded queue and display the next message after the current one finishes. Guard the worker with a flag so several messages arriving together do not open several display loops. Use concise text and reserve messages for meaningful changes.

Test mixed events

Stand on a hazard, heal, then reset while you send three notifications quickly. Check that the health bar follows the current avatar and that the queue remains ordered. Leave enough screen space between the HUD and Roblox's own controls.

Identify the health value and how it changes

Open a test place with one hazard and one healing station. Before adding the UI, inspect the character Humanoid in Explorer and confirm that these objects change Health in the expected direction. Try a different MaxHealth in a test character and check that healing stays within its limit. That separates damage problems from display problems. After that, create a track frame with a smaller colored frame inside it. Align the fill to the left edge so it grows from a consistent place. If you display a numeric label, decide whether it shows current health and maximum health or a percentage. Both can work, but test it with changing maximum values.

Update from the current Humanoid

Calculate the ratio using the current Health and MaxHealth and clamp it to a valid range. Update immediately after finding the Humanoid, then listen to both Health and MaxHealth changes. Waiting for the first event can leave a newly displayed bar blank while the player is still healthy. When the character changes, disconnect the listeners associated with the previous Humanoid before binding the replacement. The GUI can remain in PlayerGui, but its source object changes. Keep the health calculation local for rendering. The damage and healing scripts still decide the actual Humanoid values for gameplay. A display error should not change whether a player can survive a hazard.

local maxHealth = math.max(humanoid.MaxHealth, 1)
local ratio = math.clamp(humanoid.Health / maxHealth, 0, 1)
bar.Size = UDim2.fromScale(ratio, 1)

Add notifications with an explicit queue

Use another label for occasional messages such as a completed objective or a new item. Prepare a single worker that reads one queued message at a time. Show the first message, wait for a readable duration, then move to the next one. Bound the number of pending messages so a burst of gameplay events doesn't keep the label busy long after the events matter. Decide whether extra messages are dropped or combined. If every hazard contact posts a warning, the queue can fill with repeated information even while it works as designed. For a basic HUD, announce meaningful changes like getting an item or reaching a checkpoint and let the health bar show routine damage.

Make the display resilient to quick state changes

If two messages arrive in one frame, only one worker should show them in order. Set the active worker flag before starting or scheduling it. Clear that flag when the worker finishes and finishes hiding the label. If your GUI is removed because the player changes screens, end the loop and avoid writing to the old label. For health, reset the character while a warning is on screen and check for output errors. Decide whether notices belong to the current character or the current visit. A persistent inventory notification might be useful after a reset, while a warning tied to the previous encounter can be cleared as part of the change.

Test a busy scene on a small screen

Stand on the hazard, heal, then send three notifications with different text lengths. Compare their order with the order in which you added them. Reset the character in the middle of this sequence and make sure the bar reflects the new Humanoid. Disable the healing station long enough to test the low-health color and label at the bottom of the range. On a phone viewport, leave room for Roblox controls and any interaction prompt. Use the width of the fill and optional text to carry meaning even if a player can't easily distinguish the color. Once the HUD passes these tests, add transitions or theme details without changing its state logic.

Related scripts