Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ss = game:GetService("ServerStorage")
- local path1 = 1
- local pathMax = 2
- local m = {}
- function m.Move(mob)
- wait()
- local Torso = mob:WaitForChild("HumanoidRootPart")
- local h = mob:WaitForChild("Humanoid")
- -----------------------------------
- local e = mob
- local wp = game.Workspace.WP
- local sect = mob.Sect
- h.Died:Connect(function()
- e:Destroy()
- end)
- local function MoveNPC(Point, Character)
- if mob ~= nil then
- local HRP = Character.PrimaryPart
- repeat
- wait()
- Character.Humanoid:MoveTo(Point)
- --print((Vector3.new(HRP.Position.X, 0, HRP.Position.Z) - Vector3.new(Point.X, 0, Point.Z) ).magnitude)
- until (Vector3.new(HRP.Position.X, 0, HRP.Position.Z) - Vector3.new(Point.X, 0, Point.Z) ).magnitude <= 1.25
- end
- end
- local function PathWay()
- if mob.Parent ~= nil then
- local path = mob.Path
- local point = path.Value .. "_" .. sect.Value
- --print(point)
- local waypoint = wp:FindFirstChild(point)
- if waypoint then
- h:MoveTo(waypoint.Position)
- MoveNPC(waypoint.Position, e)
- else
- sect.Value = -1
- e:Destroy()
- end
- sect.Value += 1
- PathWay()
- end
- end
- PathWay()
- end
- function m.Spawn(mob, amount, timeDelay, par, path)
- local mobE = ss.Mobs:FindFirstChild(mob)
- if mobE then
- if mobE.PrimaryPart then
- if mobE.PrimaryPart:FindFirstChild("BasePos") then
- for i=1, amount do
- local mob2 = mobE:Clone()
- --Sets which path the mob will spawn on
- local pathway = path1
- if path ~= nil then
- pathway = path
- end
- mob2.Path.Value = pathway
- --Sets mob's CFrame
- if workspace.WP:FindFirstChild(pathway .. "_" .. 0) then
- mob2.PrimaryPart.CFrame = workspace.WP:FindFirstChild(pathway .. "_" .. 0).CFrame * CFrame.new(0,-mob2.PrimaryPart.BasePos.Position.Y*0.5,0)
- else
- warn(pathway .. "_" .. 0 .. " does not exist and " .. mob .. " can't be spawned")
- return nil
- end
- coroutine.wrap(m.Move)(mob2)
- if par then
- mob2.Parent = par
- else
- mob2.Parent = game.Workspace.Mobs
- end
- mob2.PrimaryPart:SetNetworkOwner(nil)
- mob2.Humanoid.Died:Connect(function()
- --task.wait(0.5)
- mob2:Destroy()
- end)
- task.wait(timeDelay)
- end
- if path == nil then
- if path1 >= pathMax then
- path1 = 0
- end
- path1 += 1
- end
- else
- warn(mob .. " does not have a BasePos and cant be spawned.")
- end
- else
- warn(mob .. " does not have a PrimaryPart and cant be spawned.")
- end
- else
- warn(mob .. " does not exist and can't be spawned.")
- end
- end
- return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement