Advertisement
Guest User

Roblox Studio - Health Bar UI Script

a guest
Dec 18th, 2022
1,579
2
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | Source Code | 2 0
  1. -- { Variables } --
  2.  
  3. local plrs = game:GetService("Players")
  4. local plr = plrs.LocalPlayer
  5. local char = plr.Character or plr.CharacterAdded:Wait()
  6. local humanoid = char:WaitForChild("Humanoid")
  7.  
  8. local UI = script.Parent
  9. local barBackground = UI:WaitForChild("BarBackground")
  10.  
  11. local bar = barBackground:WaitForChild("Bar")
  12. local percentage = barBackground.Percentage
  13.  
  14. -- { Functions } --
  15.  
  16. function healthChanged()
  17.     bar:TweenSize(
  18.         UDim2.fromScale((humanoid.Health / humanoid.MaxHealth), 1),
  19.         Enum.EasingDirection.In,
  20.         Enum.EasingStyle.Quart,
  21.         .1,
  22.         true,
  23.         nil
  24.     )
  25.    
  26.     percentage.Text = tostring(humanoid.Health).."/"..tostring(humanoid.MaxHealth)
  27. end
  28.  
  29. healthChanged()
  30. humanoid.HealthChanged:Connect(healthChanged)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement