Roblox health bar script (custom HP bar)
Replace the default health bar with your own: a bar at the bottom of the screen that slides and turns red as health drops, and an overhead bar other players can see.
LocalScriptUpdated November 28, 2026
Where to put it
LocalScript — StarterPlayer > StarterPlayerScripts > HealthBar (LocalScript). It runs on each player's device.
- In Explorer, hover StarterPlayer → StarterPlayerScripts, click
+and insert a LocalScript. Name itHealthBarand paste the code. - Nothing else is needed: the script builds the bar itself. To test, add a kill brick that deals damage (see the variation below) and press Play.
The script
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
-- Hide Roblox's default health bar.
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
local gui = Instance.new("ScreenGui")
gui.Name = "HealthBar"
gui.ResetOnSpawn = false -- one bar for the whole session
gui.Parent = player:WaitForChild("PlayerGui")
local back = Instance.new("Frame")
back.AnchorPoint = Vector2.new(0.5, 1)
back.Position = UDim2.new(0.5, 0, 1, -24)
back.Size = UDim2.new(0, 300, 0, 22)
back.BackgroundColor3 = Color3.fromRGB(35, 35, 40)
back.BorderSizePixel = 0
back.Parent = gui
local fill = Instance.new("Frame")
fill.Size = UDim2.fromScale(1, 1)
fill.BorderSizePixel = 0
fill.Parent = back
for _, frame in { back, fill } do
local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(0, 6)
corner.Parent = frame
end
local label = Instance.new("TextLabel")
label.Size = UDim2.fromScale(1, 1)
label.BackgroundTransparency = 1
label.Font = Enum.Font.GothamBold
label.TextScaled = true
label.TextColor3 = Color3.new(1, 1, 1)
label.TextStrokeTransparency = 0.5
label.ZIndex = 2
label.Parent = back
local LOW = Color3.fromRGB(230, 60, 60)
local HIGH = Color3.fromRGB(80, 220, 100)
local tweenInfo = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local function update(humanoid)
local ratio = math.clamp(humanoid.Health / math.max(humanoid.MaxHealth, 1), 0, 1)
TweenService:Create(fill, tweenInfo, {
Size = UDim2.fromScale(ratio, 1),
BackgroundColor3 = LOW:Lerp(HIGH, ratio),
}):Play()
label.Text = math.ceil(humanoid.Health) .. " / " .. math.ceil(humanoid.MaxHealth)
end
local function onCharacter(character)
local humanoid = character:WaitForChild("Humanoid")
update(humanoid)
humanoid.HealthChanged:Connect(function()
update(humanoid)
end)
humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
update(humanoid)
end)
end
if player.Character then
onCharacter(player.Character)
end
player.CharacterAdded:Connect(onCharacter)How it works
- Health lives on the server (the Humanoid), and Roblox replicates it to every client. The bar only *shows* it, so it is safe to draw in a LocalScript — damage and healing still have to happen in server Scripts.
ResetOnSpawn = falsekeeps one ScreenGui for the whole session, andCharacterAddedhooks the bar to each new Humanoid after a respawn. Without that, the bar freezes at 0 after the first death.- The fill is a Frame inside a background Frame. Its width is
Health / MaxHealthas a scale from 0 to 1, tweened so it slides instead of jumping. LOW:Lerp(HIGH, ratio)blends the color from red at 0 health to green at full health.
Variations
Health bar above every player's head
A server Script in ServerScriptService puts a BillboardGui on each character's head, so everyone sees everyone's health. It also hides Roblox's own name-and-health display for that character.
local Players = game:GetService("Players")
local function addOverheadBar(character)
local humanoid = character:WaitForChild("Humanoid")
local head = character:WaitForChild("Head")
humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
local billboard = Instance.new("BillboardGui")
billboard.Size = UDim2.new(4, 0, 0.4, 0) -- 4 studs wide
billboard.StudsOffset = Vector3.new(0, 2.5, 0)
billboard.MaxDistance = 60
billboard.Parent = head
local back = Instance.new("Frame")
back.Size = UDim2.fromScale(1, 1)
back.BackgroundColor3 = Color3.fromRGB(35, 35, 40)
back.BorderSizePixel = 0
back.Parent = billboard
local fill = Instance.new("Frame")
fill.BackgroundColor3 = Color3.fromRGB(80, 220, 100)
fill.BorderSizePixel = 0
fill.Parent = back
local function update()
fill.Size = UDim2.fromScale(math.clamp(humanoid.Health / math.max(humanoid.MaxHealth, 1), 0, 1), 1)
end
update()
humanoid.HealthChanged:Connect(update)
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(addOverheadBar)
end)A damage brick to test it
Put this Script inside a part. It takes 10 health per touch, at most once a second per player, on the server.
local Players = game:GetService("Players")
local DAMAGE = 10
local lastHit = {}
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not humanoid or not player then
return
end
if lastHit[player] and os.clock() - lastHit[player] < 1 then
return
end
lastHit[player] = os.clock()
humanoid:TakeDamage(DAMAGE)
end)
Players.PlayerRemoving:Connect(function(player)
lastHit[player] = nil
end)Bar for NPCs and bosses
Call the same addOverheadBar function on any model with a Humanoid and a Head, for example addOverheadBar(workspace.Boss). For a big boss bar at the top of the screen, reuse the LocalScript above and read workspace.Boss.Humanoid instead of the player's character.
Common mistakes
- Changing
Humanoid.Healthfrom a LocalScript to heal: it only changes on that player's screen. Healing and damage go in server Scripts. - Leaving
ResetOnSpawnon while connecting to the old Humanoid once — after the first death the bar stops moving. - Dividing by
MaxHealthwhen a script set it to 0, which gives NaN and an empty bar. Themath.max(..., 1)above prevents it. - Forgetting
SetCoreGuiEnabled(Enum.CoreGuiType.Health, false), so two health bars show at once.
FAQ
How do I make a health bar in Roblox Studio?
Add a LocalScript to StarterPlayerScripts that creates a ScreenGui with a background Frame and a fill Frame, then sets the fill's width to Humanoid.Health / Humanoid.MaxHealth whenever HealthChanged fires. The script on this page does that and also handles respawns.
How do I hide the default health bar in Roblox?
Call StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false) from a LocalScript. To hide the bar above a character's head, set that Humanoid's HealthDisplayType to AlwaysOff.
Why does my health bar stop working after I die?
When the character respawns, it gets a new Humanoid. Connect to player.CharacterAdded and hook the bar to the new Humanoid each time, and set ResetOnSpawn to false on the ScreenGui.
How do I show health above a player's head?
Put a BillboardGui on the character's Head from a server Script, with a Frame inside whose width follows Health / MaxHealth. The overhead variation on this page is a complete version.