Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Humanoid = script:WaitForChild("Humanoid").Value;
- local HealthBar = script.Parent:WaitForChild("HealthBar");
- local Main = HealthBar:WaitForChild("Main");
- local HealthText = HealthBar:WaitForChild("HealthText");
- local NameText = script.Parent:WaitForChild("NameText");
- local healthBarColors = {
- Color3.fromRGB(0,200,0);
- Color3.fromRGB(200,200,0);
- Color3.fromRGB(200,200/3*2,0);
- Color3.fromRGB(200,0,0);
- Color3.fromRGB(200/3,0,0);
- };
- local function rangePercentage(input,min,max)
- return ((input-min)*100)/(max-min);
- end;
- Main.BackgroundColor3 = healthBarColors[1];
- local function updateBar(health,maxHealth)
- NameText.Text = Humanoid.DisplayName ~= ""
- and Humanoid.DisplayName or Humanoid.Parent.Name;
- NameText.Text = string.upper(NameText.Text);
- HealthText.Text = string.format("%02i / %02i",health,maxHealth);
- Main.Size = UDim2.new(health/maxHealth,0,1,0);
- if health/maxHealth <= 0.2 then
- local alpha = 1 - rangePercentage(health,0,maxHealth*0.2)/100;
- Main.BackgroundColor3 = healthBarColors[4]:lerp(healthBarColors[5],alpha);
- elseif health/maxHealth <= 1/3 then
- local alpha = 1 - rangePercentage(health,maxHealth*0.2,maxHealth*(1/3))/100;
- Main.BackgroundColor3 = healthBarColors[3]:lerp(healthBarColors[4],alpha);
- elseif health/maxHealth <= 0.5 then
- local alpha = 1 - rangePercentage(health,maxHealth*(1/3),maxHealth*0.5)/100;
- Main.BackgroundColor3 = healthBarColors[2]:lerp(healthBarColors[3],alpha);
- else
- local alpha = 1 - rangePercentage(health,maxHealth*0.5,maxHealth)/100;
- Main.BackgroundColor3 = healthBarColors[1]:lerp(healthBarColors[2],alpha);
- end;
- end;
- updateBar(Humanoid.Health,Humanoid.MaxHealth);
- Humanoid.HealthChanged:Connect(function(health)
- updateBar(health,Humanoid.MaxHealth);
- end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement