Advertisement
Hasli4

RBLX. HealthBar

May 12th, 2025
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.78 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local HitPoints = script.Parent.Front
  3. local container = HitPoints.Parent
  4.  
  5. local function onHealthChanged()
  6.     local human = player.Character.Humanoid
  7.     local percent = human.Health / human.MaxHealth
  8.     HitPoints.Size = UDim2.new(percent, 0, 1, 0)
  9.     if percent < .1 then
  10.         HitPoints.BackgroundColor3 = Color3.new(1, 0, 0)
  11.     elseif percent < .4 then
  12.         HitPoints.BackgroundColor3 = Color3.new(1, 1, 0)
  13.     else
  14.         HitPoints.BackgroundColor3 = Color3.new(0, 1, 0)
  15.     end
  16. end
  17. local function onCharacterAdded(character)
  18.     local human = character:WaitForChild("Humanoid")
  19.     human.HealthChanged:Connect(onHealthChanged)
  20.     onHealthChanged()
  21. end
  22. player.CharacterAdded:Connect(onCharacterAdded)
  23. if player.Character then
  24.     onCharacterAdded(player.Character)
  25. end
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement