Advertisement
Anukun_Lucifer

HealthScript(EP.10)

Feb 11th, 2024
1,723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | Gaming | 0 0
  1. local Player = game:GetService("Players")
  2.  
  3. local health = {}
  4.  
  5. function health.Setup(model ,screenGui)
  6.     local newHealthBar = script.HealthGui:Clone()
  7.     newHealthBar.Adornee = model:WaitForChild("Head")
  8.     newHealthBar.Parent = Player.LocalPlayer.PlayerGui:WaitForChild("Billboards")
  9.  
  10.     if model.Name == "Base" then
  11.         newHealthBar.MaxDistance = 100
  12.         newHealthBar.Size = UDim2.new(0,150,0,30)
  13.     else
  14.         newHealthBar.MaxDistance = 30
  15.         newHealthBar.Size = UDim2.new(0,150,0,20)
  16.     end
  17.  
  18.     health.UpdateHealth(newHealthBar, model)
  19.     if screenGui then
  20.         health.UpdateHealth(screenGui, model)
  21.     end
  22.    
  23.     model.Humanoid.HealthChanged:Connect(function()
  24.         health.UpdateHealth(newHealthBar, model)
  25.        
  26.         if screenGui then
  27.             health.UpdateHealth(screenGui, model)
  28.         end
  29.     end)
  30.    
  31. end
  32.  
  33. function health.UpdateHealth(gui, model)
  34.     local humanoid = model:WaitForChild("Humanoid")
  35.    
  36.     if humanoid and gui then
  37.         local percent = humanoid.Health / humanoid.MaxHealth
  38.         gui.CurrentHealth.Size = UDim2.new(math.max(percent,0),0,1,0)
  39.        
  40.         if humanoid.Health <= 0 then
  41.             if model.Name == "Base" then
  42.                 gui.Title.Text = model.Name .. "DESTROYED"
  43.             else
  44.                 gui.Title.Text = model.Name .. "DEAD"
  45.                 task.wait(0.5)
  46.                 gui:Destroy()
  47.             end
  48.  
  49.         else
  50.             gui.Title.Text =  model.Name.. ":" .. humanoid.Health .."/".. humanoid.MaxHealth
  51.         end
  52.     end
  53.    
  54. end
  55.  
  56. return health
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement