Advertisement
Anukun_Lucifer

MobScript (ModuleScript) (EP07)

Nov 25th, 2023
2,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | Gaming | 0 0
  1. local physicsservice = game:GetService("PhysicsService")
  2. local serverstorage = game:GetService("ServerStorage")
  3. local serverstorage = game:GetService("ServerStorage")
  4.  
  5. local bindables = serverstorage:WaitForChild("Bindables")
  6. local updateasehealthEvent = bindables:WaitForChild("UpdateBaseHealth")
  7.  
  8. local mob = {}
  9.  
  10. function mob.Move(mob, map)
  11.     local humanoid = mob:WaitForChild("Humanoid")
  12.     local waypoints = map.Waypoints
  13.  
  14.     for waypoint = 1, #waypoints:GetChildren() do
  15.         humanoid:MoveTo(waypoints[waypoint].Position)
  16.         humanoid.MoveToFinished:Wait()
  17.     end
  18.    
  19.     mob:Destroy()
  20.    
  21.     updateasehealthEvent:Fire(humanoid.Health)
  22.    
  23. end
  24.  
  25. function mob.Spawn(name, quantity, map)
  26.     local mobExists = serverstorage.Mobs:FindFirstChild(name)
  27.    
  28.     if mobExists then
  29.         for i=1, quantity do
  30.             task.wait(0.5)
  31.             local newMob = mobExists:Clone()
  32.             newMob.HumanoidRootPart.CFrame = map.Start.CFrame
  33.             newMob.Parent = map.Mob
  34.             newMob.HumanoidRootPart:SetNetworkOwner(nil)
  35.            
  36.             for i, object in ipairs(newMob:GetDescendants()) do
  37.                 if object:IsA("BasePart") then
  38.                     physicsservice:SetPartCollisionGroup(object, "Mob")
  39.                 end
  40.             end
  41.            
  42.             newMob.Humanoid.Died:Connect(function()
  43.                 task.wait(0.5)
  44.                 newMob:Destroy()
  45.             end)
  46.            
  47.             coroutine.wrap(mob.Move)(newMob, map)
  48.         end
  49.     else
  50.         warn("Requested mob dose not exist",name)
  51.     end
  52. end
  53.  
  54. return mob
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement