Advertisement
XxSpiritDuoxX

a

Mar 11th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. local ss = game:GetService("ServerStorage")
  2. local path1 = 1
  3. local pathMax = 2
  4. local m = {}
  5.  
  6. function m.Move(mob)
  7. wait()
  8. local Torso = mob:WaitForChild("HumanoidRootPart")
  9.  
  10. local h = mob:WaitForChild("Humanoid")
  11.  
  12. -----------------------------------
  13.  
  14. local e = mob
  15. local wp = game.Workspace.WP
  16. local sect = mob.Sect
  17.  
  18. h.Died:Connect(function()
  19. e:Destroy()
  20. end)
  21.  
  22. local function MoveNPC(Point, Character)
  23. if mob ~= nil then
  24. local HRP = Character.PrimaryPart
  25. repeat
  26. wait()
  27. Character.Humanoid:MoveTo(Point)
  28. --print((Vector3.new(HRP.Position.X, 0, HRP.Position.Z) - Vector3.new(Point.X, 0, Point.Z) ).magnitude)
  29. until (Vector3.new(HRP.Position.X, 0, HRP.Position.Z) - Vector3.new(Point.X, 0, Point.Z) ).magnitude <= 1.25
  30. end
  31. end
  32.  
  33. local function PathWay()
  34. if mob.Parent ~= nil then
  35. local path = mob.Path
  36. local point = path.Value .. "_" .. sect.Value
  37. --print(point)
  38. local waypoint = wp:FindFirstChild(point)
  39. if waypoint then
  40. h:MoveTo(waypoint.Position)
  41. MoveNPC(waypoint.Position, e)
  42. else
  43. sect.Value = -1
  44. e:Destroy()
  45. end
  46. sect.Value += 1
  47. PathWay()
  48. end
  49. end
  50. PathWay()
  51. end
  52.  
  53. function m.Spawn(mob, amount, timeDelay, par, path)
  54. local mobE = ss.Mobs:FindFirstChild(mob)
  55.  
  56. if mobE then
  57. if mobE.PrimaryPart then
  58. if mobE.PrimaryPart:FindFirstChild("BasePos") then
  59. for i=1, amount do
  60. local mob2 = mobE:Clone()
  61. --Sets which path the mob will spawn on
  62. local pathway = path1
  63. if path ~= nil then
  64. pathway = path
  65. end
  66. mob2.Path.Value = pathway
  67. --Sets mob's CFrame
  68. if workspace.WP:FindFirstChild(pathway .. "_" .. 0) then
  69. mob2.PrimaryPart.CFrame = workspace.WP:FindFirstChild(pathway .. "_" .. 0).CFrame * CFrame.new(0,-mob2.PrimaryPart.BasePos.Position.Y*0.5,0)
  70. else
  71. warn(pathway .. "_" .. 0 .. " does not exist and " .. mob .. " can't be spawned")
  72. return nil
  73. end
  74.  
  75. coroutine.wrap(m.Move)(mob2)
  76.  
  77. if par then
  78. mob2.Parent = par
  79. else
  80. mob2.Parent = game.Workspace.Mobs
  81. end
  82. mob2.PrimaryPart:SetNetworkOwner(nil)
  83.  
  84. mob2.Humanoid.Died:Connect(function()
  85. --task.wait(0.5)
  86. mob2:Destroy()
  87. end)
  88.  
  89. task.wait(timeDelay)
  90. end
  91. if path == nil then
  92. if path1 >= pathMax then
  93. path1 = 0
  94. end
  95. path1 += 1
  96. end
  97. else
  98. warn(mob .. " does not have a BasePos and cant be spawned.")
  99. end
  100. else
  101. warn(mob .. " does not have a PrimaryPart and cant be spawned.")
  102. end
  103. else
  104. warn(mob .. " does not exist and can't be spawned.")
  105. end
  106. end
  107.  
  108. return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement