Advertisement
Cakey3101

Health Bar System

Jun 14th, 2025
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. local Player = Players.LocalPlayer
  4. local Character = Player.Character or Player.CharacterAdded:Wait()
  5. local Humanoid: Humanoid = Character:FindFirstChild("Humanoid")
  6.  
  7. local HealthBar = script.Parent.HealthBackground.HealthBar
  8. local PercentageLabel = HealthBar.Parent.TextLabel
  9.  
  10. local function UpdateHealthBar()
  11.     local XSize = math.clamp(Humanoid.Health / Humanoid.MaxHealth, 0, 1)
  12.     HealthBar:TweenSize(UDim2.fromScale(XSize, 1), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5)
  13.     PercentageLabel.Text = `{tostring(math.floor(XSize * 100))}%`
  14. end
  15.  
  16. UpdateHealthBar()
  17.  
  18. Humanoid:GetPropertyChangedSignal("Health"):Connect(UpdateHealthBar)
  19. Humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(UpdateHealthBar)
Tags: robloxstudio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement