0 views0 copies0 likes

Health Bar for New and Returning Characters

Universal script

Copy it, then test it in your own Studio place.

UI systems Verified

Script code

22 lines ยท 1.1 KB
Download
local player = game:GetService("Players").LocalPlayerlocal gui = Instance.new("ScreenGui", player:WaitForChild("PlayerGui"))gui.ResetOnSpawn = falselocal track = Instance.new("Frame", gui)track.Position, track.Size = UDim2.fromOffset(22, 105), UDim2.fromOffset(200, 17)track.BackgroundColor3 = Color3.fromRGB(35, 38, 51)local bar = Instance.new("Frame", track)local healthConnection, maxConnectionlocal function bind(character)	if healthConnection then healthConnection:Disconnect(); maxConnection:Disconnect() end	local characterHumanoid = character:WaitForChild("Humanoid")	local function refresh()		local ratio = math.clamp(characterHumanoid.Health / math.max(1, characterHumanoid.MaxHealth), 0, 1)		bar.Size = UDim2.fromScale(ratio, 1)-- โ€ฆopen Get script for the full source

About this script

Put this LocalScript into StarterPlayerScripts to show a compact health bar outside combat menus. It rebinds to the new Humanoid when the character resets, updates when Health or MaxHealth changes, and shifts from red to green as health rises. Test with a hazard and a healing station, then customize its position to avoid overlapping your other HUD elements.

Comments

Share what works, ask questions, or report an issue.

0

Log in to leave a comment.

No comments yet

Be the first to share your thoughts!

Raw Luau source

local player = game:GetService("Players").LocalPlayer
local gui = Instance.new("ScreenGui", player:WaitForChild("PlayerGui"))
gui.ResetOnSpawn = false
local track = Instance.new("Frame", gui)
track.Position, track.Size = UDim2.fromOffset(22, 105), UDim2.fromOffset(200, 17)
track.BackgroundColor3 = Color3.fromRGB(35, 38, 51)
local bar = Instance.new("Frame", track)
local healthConnection, maxConnection
local function bind(character)
	if healthConnection then healthConnection:Disconnect(); maxConnection:Disconnect() end
	local characterHumanoid = character:WaitForChild("Humanoid")
	local function refresh()
		local ratio = math.clamp(characterHumanoid.Health / math.max(1, characterHumanoid.MaxHealth), 0, 1)
		bar.Size = UDim2.fromScale(ratio, 1)
		bar.BackgroundColor3 = Color3.fromRGB(255, 79, 93):Lerp(Color3.fromRGB(73, 235, 138), ratio)
	end
	healthConnection = characterHumanoid.HealthChanged:Connect(refresh)
	maxConnection = characterHumanoid:GetPropertyChangedSignal("MaxHealth"):Connect(refresh)
	refresh()
end
player.CharacterAdded:Connect(bind)
if player.Character then task.spawn(bind, player.Character) end