Advertisement
Anukun_Lucifer

BaseScript (ModuleScript) (EP07)

Nov 25th, 2023
2,311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | Gaming | 0 0
  1. local serverstorage = game:GetService("ServerStorage")
  2.  
  3. local bindables = serverstorage:WaitForChild("Bindables")
  4. local updateasehealthEvent = bindables:WaitForChild("UpdateBaseHealth")
  5. local gameoverEvent = bindables:WaitForChild("GameOver")
  6.  
  7. local base = {}
  8.  
  9. function base.Setup(map, health)
  10.     base.Model = map:WaitForChild("Base")
  11.     base.CurrentHealth = health
  12.     base.MaxHealth = health
  13.    
  14.     base.UpdateHealth()
  15. end
  16.  
  17. function base.UpdateHealth(damage)
  18.     if damage then
  19.         base.CurrentHealth -= damage
  20.     end
  21.    
  22.     local gui = base.Model.HealthGui
  23.     local percent = base.CurrentHealth / base.MaxHealth
  24.    
  25.     gui.CurrentHealth.Size = UDim2.new(percent,0,0.5,0)
  26.    
  27.     if base.CurrentHealth <= 0 then
  28.         gameoverEvent:Fire()
  29.         gui.Title.Text = "Base: DESTROYED"
  30.     else
  31.         gui.Title.Text = "Base: ".. base.CurrentHealth .."/".. base.MaxHealth
  32.     end
  33.    
  34. end
  35.  
  36. updateasehealthEvent.Event:Connect(base.UpdateHealth)
  37.  
  38. return base
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement