Advertisement
Anukun_Lucifer

MobScript

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