JJBloxxer

Custom Health Bar

Jan 25th, 2021
1,785
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local players = game:GetService("Players");
  2. local runService = game:GetService("RunService");
  3.  
  4. local localPlayer = players.LocalPlayer;
  5.  
  6. local screenGui = script.Parent;
  7. local healthBar = screenGui.Health;
  8. local bar = healthBar.Bar;
  9. local amount = healthBar.Amount;
  10.  
  11. runService.RenderStepped:Connect(function()
  12.     local character = localPlayer.Character;
  13.     local humanoid = character and character.Humanoid;
  14.    
  15.     if character and humanoid then
  16.         local health = humanoid.Health;
  17.         local maxHealth = humanoid.MaxHealth;
  18.        
  19.         local xScale = (health / maxHealth);
  20.        
  21.         bar:TweenSize(UDim2.new(xScale, 0, 1, 0), "Out", "Sine", 0.1, true);
  22.         amount.Text = math.floor(health + 0.5);
  23.     end
  24. end);
RAW Paste Data