Advertisement
IHATEMICROWAVEOVEN

EnemyLoader Module

Aug 3rd, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. -- WELDING
  2.  
  3. local function Weld(P0, P1, WeldPoint)
  4. local Weld = Instance.new("Weld", P1)
  5. Weld.Part0 = P0
  6. Weld.Part1 = P1
  7. Weld.C0 = P0.CFrame:inverse() * P1.CFrame
  8. return Weld
  9. end
  10.  
  11. for _, Boss in pairs(script.Parent:GetChildren()) do
  12. if Boss:IsA'Model' then
  13. for _, Child in pairs(Boss:GetChildren()) do
  14. if Child:IsA'BasePart' then
  15. if Boss:FindFirstChild("E"..Child.Name) then
  16. for _, Part in pairs(Boss["E"..Child.Name]:GetChildren()) do
  17. if Part:IsA'BasePart' and Part.Name ~= "Middle" then
  18. Weld(Child, Part)
  19. Part.Anchored = false
  20. Part.CanCollide = false
  21. end
  22. end
  23. end
  24. Child.Anchored = false
  25. end
  26. end
  27. end
  28. end
  29.  
  30.  
  31. -- ~~BOSS~~ Enem HANDLING
  32.  
  33. local Stats = require(game:GetService("ServerScriptService"):WaitForChild("Stats"))
  34.  
  35. -- COPYING ~~BOSSES~~ enemy
  36.  
  37. local Enemies = {}
  38.  
  39. local EneData = {}
  40.  
  41. function EnemySpawn(enename)
  42. EneData[enename].Character = Enemies[enename]:Clone()
  43. EneData[enename].Character.Parent = script.Parent
  44. require(EneData[enename].Character.Behavior)()
  45. if script:FindFirstChild(enename.."Reward") then require(script[enename.."Reward"])(Stats,EneData[enename].Character) end -- Rewards not moved into the sibling model because it would get cloned unnecessarily
  46. EneData[enename].Character:Destroy()
  47. EneData[enename].Character = nil
  48. end
  49.  
  50. for _, i in pairs(script.Parent:GetChildren()) do
  51. if i.Name ~= script.Name then
  52. Enemies[i.Name] = i:Clone()
  53. i:Destroy()
  54. EneData[i.Name] = {
  55. Character = nil,
  56. Respawn = Enemies[i.Name]:FindFirstChild("Respawn") and Enemies[i.Name].Respawn.Value or 20
  57. }
  58. coroutine.wrap(function()
  59. while true do
  60. EnemySpawn(i.Name)
  61. print(EneData[i.Name].Respawn)
  62. wait(EneData[i.Name].Respawn)
  63. print("888888888888888888888888888888")
  64. end
  65. end)()
  66. end
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement