**Hi Im CTG I Need help in Module Script **
Im Making My Zombie Spawn Zombie But Idk Why When It Spawn Done The Zombie Is Go Back Waypoints 1(Not The Zombie Spawn Waypoint) And When The Summon Zombie Die It Stuck
Zombie Module
local PhysicsService = game:GetService("PhysicsService")
local ServerStorage = game:GetService("ServerStorage")
local TweenService = game:GetService("TweenService")
local function setNetworkOwnerOfModel(model, networkOwner)
for _, descendant in pairs(model:GetDescendants()) do
if descendant:IsA("BasePart") then
local success, errorReason = descendant:CanSetNetworkOwnership()
if success then
descendant:SetNetworkOwner(networkOwner)
else
error(errorReason)
end
end
end
end
local mob2 = {}
function mob2.Move(mob2, Map)
local humanoid = mob2:WaitForChild("Humanoid")
local waypoints = Map.Waypoints
if humanoid then
for waypoint=1, #waypoints:GetChildren() do
mob2.MovingTo.Value = waypoint
repeat humanoid:MoveTo(waypoints[waypoint].Position)
until humanoid.MoveToFinished:Wait()
end
mob2:Destroy()
Map.Base.Humanoid:TakeDamage(humanoid.Health)
end
end
function mob2.Spawn(name, quantity, Map, hum, MovingToNpc)
print(name, quantity, Map, MovingToNpc)
local mob2Exists = ServerStorage.Mobs:FindFirstChild(name)
local Map = workspace.Map:FindFirstChildOfClass("Folder")
if mob2Exists then
for i=1, quantity do
task.wait(0.5)
local newmob2 = mob2Exists:Clone()
newmob2.HumanoidRootPart.CFrame = hum
newmob2.Parent = workspace.Mobs
newmob2.HumanoidRootPart:SetNetworkOwner(nil)
print(newmob2.Name)
local MovingTo = Instance.new("NumberValue")
MovingTo.Name = "MovingTo"
MovingTo.Parent = newmob2
MovingTo.Value = tonumber(MovingToNpc)
local MovingToSummon = Instance.new("BoolValue")
MovingToSummon.Name = "MovingToSummon"
MovingToSummon.Parent = newmob2
local ZombieTag = Instance.new("BoolValue")
ZombieTag.Name = "ZombieTag"
ZombieTag.Parent = newmob2
for i, object in ipairs(newmob2:GetDescendants()) do
if object:IsA("BasePart") then
--setNetworkOwnerOfModel(object, "Mob")
PhysicsService:SetPartCollisionGroup(object, "Mob")
end
end
newmob2.Humanoid.Died:Connect(function()
task.wait(1)
newmob2:Destroy()
end)
coroutine.wrap(mob2.Move)(newmob2, Map)
end
else
warn("mob2 Not Exist: ", name)
end
end
return mob2
Summon Script
while wait(7) do
print("work")
local randomSpawn = math.random(1,3)
print(randomSpawn)
if randomSpawn == 1 then
print("Normal")
script.Parent.Humanoid.WalkSpeed = 0
local Main = game:GetService("ServerScriptService").Main
local Mob2 = require(Main.Mob2)
Mob2.Spawn("Normal", 1, workspace.Mobs, script.Parent.HumanoidRootPart.CFrame, script.Parent.MovingTo.Value)
print("Mob MovingTo Is: "..script.Parent.MovingTo.Value)
local hum = script.Parent.Humanoid
local animation = script.Parent.Animations.Summon
local summonAnim = hum:LoadAnimation(animation)
summonAnim:Play()
wait(0.5)
script.Parent.Humanoid.WalkSpeed = 5
summonAnim:Stop()
elseif randomSpawn == 2 then
print("Speedy")
script.Parent.Humanoid.WalkSpeed = 0
local Main = game:GetService("ServerScriptService").Main
local Mob2 = require(Main.Mob2)
Mob2.Spawn("Speedy", 1, workspace.Mobs, script.Parent.HumanoidRootPart.CFrame, script.Parent.MovingTo.Value)
print("Mob MovingTo Is: "..script.Parent.MovingTo.Value)
local hum = script.Parent.Humanoid
local animation = script.Parent.Animations.Summon
local summonAnim = hum:LoadAnimation(animation)
summonAnim:Play()
wait(0.5)
script.Parent.Humanoid.WalkSpeed = 5
summonAnim:Stop()
elseif randomSpawn == 3 then
print("Slower")
script.Parent.Humanoid.WalkSpeed = 0
local Main = game:GetService("ServerScriptService").Main
local Mob2 = require(Main.Mob2)
Mob2.Spawn("Slower", 1, workspace.Mobs, script.Parent.HumanoidRootPart.CFrame, script.Parent.MovingTo.Value)
print("Mob MovingTo Is: "..script.Parent.MovingTo.Value)
local hum = script.Parent.Humanoid
local animation = script.Parent.Animations.Summon
local summonAnim = hum:LoadAnimation(animation)
summonAnim:Play()
wait(0.5)
script.Parent.Humanoid.WalkSpeed = 5
summonAnim:Stop()
end
end