Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local Player = Players.LocalPlayer
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local Humanoid: Humanoid = Character:FindFirstChild("Humanoid")
- local HealthBar = script.Parent.HealthBackground.HealthBar
- local PercentageLabel = HealthBar.Parent.TextLabel
- local function UpdateHealthBar()
- local XSize = math.clamp(Humanoid.Health / Humanoid.MaxHealth, 0, 1)
- HealthBar:TweenSize(UDim2.fromScale(XSize, 1), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5)
- PercentageLabel.Text = `{tostring(math.floor(XSize * 100))}%`
- end
- UpdateHealthBar()
- Humanoid:GetPropertyChangedSignal("Health"):Connect(UpdateHealthBar)
- Humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(UpdateHealthBar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement