I'm trying to make a zombie survival game and currently i'm working on the zombie spawning mechanism. It does spawn the zombies, but they fly around everywhere and kill each other and stuff. I have absolutely no clue why this is happening lol.
Spawn zombies script:
local Zombie = game.ReplicatedStorage.Zombie
local Round = game.Workspace.Round.Value
local RoundEvent = game.ReplicatedStorage.RoundChanged
local ZombiesSpawned = Instance.new("IntValue")
ZombiesSpawned.Parent = game.ReplicatedStorage
ZombiesSpawned.Value = 0
ZombiesSpawned.Name = "ZombiesSpawned"
local ZombiesSpawnedValue = game.ReplicatedStorage:WaitForChild("ZombiesSpawned")
local function SpawnZombiesRound1()
for i = 0, 10 do
local ZombieClone = Zombie:Clone()
ZombieClone.Parent = game.Workspace
ZombieClone:WaitForChild("Torso").Position = Vector3.new(math.random(-49, 0), 17, math.random(0, 37))
end
end
if Round == 1 then
SpawnZombiesRound1()
end
RoundEvent.OnServerEvent:Connect(function()
game.Workspace.Round.Value = game.Workspace.Round.Value + 1
end)
Zombie script:
local ZombieTorso = script.Parent.Torso
local ZombieHumanoid = script.Parent.Humanoid
local function FindTarget ()
local AggroDistance = 100
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local humanRootPart = v:FindFirstChild("HumanoidRootPart")
if humanRootPart and v.Parent.Name ~= "Zombie" then
if (ZombieTorso.Position - humanRootPart.Position).magnitude <= AggroDistance then
AggroDistance = (ZombieTorso.Position - humanRootPart.Position).magnitude
target = humanRootPart
end
end
end
return target
end
while wait(1) do
local torso = FindTarget()
if torso then
ZombieHumanoid:MoveTo(torso.Position)
ZombieHumanoid.MoveToFinished:Connect(function()
torso.Parent:FindFirstChild("Humanoid").Health = 0
end)
else
wait(1)
ZombieHumanoid:MoveTo(ZombieTorso.Position + Vector3.new(math.random(-50, 50), 0, math.random(-50, 50 )))
end
end
Video (sorry for potato quality): https://youtu.be/ihOy4clzzMg

2 comments
I can't access your YouTube video because it is private. You had to make the video unlisted or public.
oh sorry should be fixed now