Hey guys, I want to make a health bar for a game and I found this script and I added on to it.
But I need your option if this is good or not.
Thanks and here’s the script:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
– Create a simple health bar
local healthBar = Instance.new(“Frame”)
healthBar.Name = “SimpleHealthBar”
healthBar.AnchorPoint = Vector2.new(0.5, 0.5)
healthBar.Position = UDim2.new(0.5, 0, 0.9, 0) – Bottom center of screen
healthBar.Size = UDim2.new(0.3, 0, 0.03, 0) – Width, Height
healthBar.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
healthBar.BorderSizePixel = 1
healthBar.Parent = player.PlayerGui:WaitForChild(“PlayerGui”) or player:WaitForChild(“PlayerGui”)
local healthFill = Instance.new(“Frame”)
healthFill.Name = “HealthFill”
healthFill.Size = UDim2.new(1, 0, 1, 0) – Starts full
healthFill.BackgroundColor3 = Color3.new(1, 0, 0) – Red
healthFill.BorderSizePixel = 0
healthFill.Parent = healthBar
– Update health bar when health changes
humanoid.HealthChanged:Connect(function(health)
local healthPercent = health / humanoid.MaxHealth
healthFill.Size = UDim2.new(healthPercent, 0, 1, 0)
-- Change color based on health (optional)
if healthPercent > 0.5 then
healthFill.BackgroundColor3 = Color3.new(0, 1, 0) -- Green when above 50%
else
healthFill.BackgroundColor3 = Color3.new(1, 0, 0) -- Red when below 50%
end
end)
- Is this a good health bar script
- Yes
- No
- Would this script work?
- Yes
- No