Hasli4

RBLX. HealthBar

Jan 14th, 2026
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2.  
  3. local HitPoints = script.Parent.Front
  4.  
  5. local container = HitPoints.Parent
  6.  
  7. local function onHealthChanged()
  8.  
  9.         local human = player.Character.Humanoid
  10.  
  11.         local percent = human.Health / human.MaxHealth
  12.  
  13.         HitPoints.Size = UDim2.new(percent, 0, 1, 0)
  14.  
  15.         if percent < .1 then
  16.  
  17.                 HitPoints.BackgroundColor3 = Color3.new(1, 0, 0)
  18.  
  19.         elseif percent < .4 then
  20.  
  21.                 HitPoints.BackgroundColor3 = Color3.new(1, 1, 0)
  22.  
  23.         else
  24.  
  25.                 HitPoints.BackgroundColor3 = Color3.new(0, 1, 0)
  26.  
  27.         end
  28.  
  29. end
  30.  
  31. local function onCharacterAdded(character)
  32.  
  33.         local human = character:WaitForChild("Humanoid")
  34.  
  35.         human.HealthChanged:Connect(onHealthChanged)
  36.  
  37.         onHealthChanged()
  38.  
  39. end
  40.  
  41. player.CharacterAdded:Connect(onCharacterAdded)
  42.  
  43. if player.Character then
  44.  
  45.         onCharacterAdded(player.Character)
  46.  
  47. end
Advertisement
Add Comment
Please, Sign In to add comment