Advertisement
Guest User

Health bar script

a guest
Apr 22nd, 2021
1,832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. local TW = game:GetService("TweenService")--Get Tween Service
  2.  
  3. local Player = game:GetService("Players").LocalPlayer --Get The Player
  4. local Character = Player.Character or Player.CharacterAdded:Wait() --Wait For The Player Humanoid
  5. local Humanoid = Character:WaitForChild("Humanoid") --Get The Player Humanoid
  6.  
  7. local Healthbar = script.Parent -- Get The Health Bar
  8.  
  9. local function UpdateHealthbar() --Health Bar Size Change Function
  10. local health = math.clamp(Humanoid.Health / Humanoid.MaxHealth, 0, 1) --Maths
  11. local info = TweenInfo.new(Humanoid.Health / Humanoid.MaxHealth,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0) --Tween Info
  12. TW:Create(script.Parent,info,{Size = UDim2.fromScale(health, 1)}):Play() -- Create The Tween Then Play It
  13. end
  14.  
  15. UpdateHealthbar()--Update The Health Bar
  16.  
  17. Humanoid:GetPropertyChangedSignal("Health"):Connect(UpdateHealthbar) --Update The Health Bar When The Health Change
  18. Humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(UpdateHealthbar) --Update The Health Bar Wheb The MaxHealth Change
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement