Advertisement
xmaanzach

HealthBar Tutorial

May 25th, 2019
25,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. local StarterGui = game:GetService("StarterGui")
  2.  
  3. StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
  4.  
  5. local HealthText = script.Parent.Vida
  6. local Bar = script.Parent.Bar
  7. local Player = game.Players.LocalPlayer
  8.  
  9. repeat wait() until Player.Character or Player.CharacterAdded:Wait()
  10.  
  11. local Character = Player.Character
  12. local Humanoid = Character:FindFirstChild("Humanoid")
  13.  
  14. local GreenColor = Color3.fromRGB(0, 170, 0)
  15. local RedColor = Color3.fromRGB(170, 0, 0)
  16. local YellowColor = Color3.fromRGB(154, 154, 0)
  17.  
  18. Humanoid.HealthChanged:Connect(function(Health)
  19.  
  20. local Health = math.floor(Health)
  21.  
  22. Bar.Size = UDim2.new(0, Health*2, 0, 20)
  23.  
  24. HealthText.Text = tostring(Health .. "%")
  25.  
  26. if Health >= 75 then
  27. Bar.BackgroundColor3 = GreenColor
  28.  
  29. elseif Health < 60 and Health > 40 then
  30. Bar.BackgroundColor3 = YellowColor
  31.  
  32. elseif Health < 40 then
  33. Bar.BackgroundColor3 = RedColor
  34. end
  35. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement