Advertisement
Sungmingamerpro13

BossHealthGui(STORY GAME)

Dec 16th, 2022
1,217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.75 KB | None | 0 0
  1. local Humanoid = script:WaitForChild("Humanoid").Value;
  2.  
  3. local HealthBar = script.Parent:WaitForChild("HealthBar");
  4. local Main = HealthBar:WaitForChild("Main");
  5. local HealthText = HealthBar:WaitForChild("HealthText");
  6. local NameText = script.Parent:WaitForChild("NameText");
  7.  
  8. local healthBarColors = {
  9.     Color3.fromRGB(0,200,0);
  10.     Color3.fromRGB(200,200,0);
  11.     Color3.fromRGB(200,200/3*2,0);
  12.     Color3.fromRGB(200,0,0);
  13.     Color3.fromRGB(200/3,0,0);
  14. };
  15.  
  16. local function rangePercentage(input,min,max)
  17.     return ((input-min)*100)/(max-min);
  18. end;
  19.  
  20. Main.BackgroundColor3 = healthBarColors[1];
  21.  
  22. local function updateBar(health,maxHealth)
  23.     NameText.Text = Humanoid.DisplayName ~= ""
  24.     and Humanoid.DisplayName or Humanoid.Parent.Name;
  25.     NameText.Text = string.upper(NameText.Text);
  26.    
  27.     HealthText.Text = string.format("%02i / %02i",health,maxHealth);
  28.     Main.Size = UDim2.new(health/maxHealth,0,1,0);
  29.    
  30.     if health/maxHealth <= 0.2 then
  31.         local alpha = 1 - rangePercentage(health,0,maxHealth*0.2)/100;
  32.         Main.BackgroundColor3 = healthBarColors[4]:lerp(healthBarColors[5],alpha);
  33.     elseif health/maxHealth <= 1/3 then
  34.         local alpha = 1 - rangePercentage(health,maxHealth*0.2,maxHealth*(1/3))/100;
  35.         Main.BackgroundColor3 = healthBarColors[3]:lerp(healthBarColors[4],alpha);
  36.     elseif health/maxHealth <= 0.5 then
  37.         local alpha = 1 - rangePercentage(health,maxHealth*(1/3),maxHealth*0.5)/100;
  38.         Main.BackgroundColor3 = healthBarColors[2]:lerp(healthBarColors[3],alpha);
  39.     else
  40.         local alpha = 1 - rangePercentage(health,maxHealth*0.5,maxHealth)/100;
  41.         Main.BackgroundColor3 = healthBarColors[1]:lerp(healthBarColors[2],alpha);
  42.     end;
  43. end;
  44.  
  45. updateBar(Humanoid.Health,Humanoid.MaxHealth);
  46. Humanoid.HealthChanged:Connect(function(health)
  47.     updateBar(health,Humanoid.MaxHealth);
  48. end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement