When I spawn more than one zombie, the whole thing breaks. I’ve ran some code to debug it and the whole code works; it’s going through every statement and well but yet the zombies are stationary. They don’t even deal damage.
Maybe it’s the move-to command not working properly but there are no alternatives that work. Path finding is completely bugged in this script.
Here’s an example of the behaviour:
Once again, maybe the move command cannot handle this
Zombie script:
local ai = {}
local renderservice = game:GetService("RunService")
function ai.Follow(plr, humrootpart)
local hum = script.Parent.Zombie
local hitbox = script.Parent.HitBox
local animator = hum.Animator
local animid_kill = script.ZombieAttack
local animid_killgo = hum:LoadAnimation(animid_kill)
local distance = nil
local debounce2 = false
local direction = nil
local zombieroot = script.Parent.HumanoidRootPart
local debounce = false
local Conn = renderservice.Heartbeat:Connect(function()
local mag = (humrootpart.Position - zombieroot.Position)
distance = mag.Magnitude
direction = mag.Unit
hitbox.Touched:Once(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
hit.Parent.Humanoid:TakeDamage(5)
animid_killgo:Play()
print("works!")
task.wait(1)
debounce = false
end
end
end)
if distance <=100 then
hum:Move(direction)
elseif distance >= 100 then
hum:Move(Vector3.new(math.random(50,50)))
end
end)
plr.Character.Humanoid.Died:Once(function()
Conn:Disconnect()
end)
end
return ai
Zombie spawner script:
local wavesystem = {}
function wavesystem.Setup()
print("func")
local serverstorage = game:GetService("ServerStorage")
local amount = 0
print("wee")
local function wave1()
while true do
task.wait(0.1)
local undead = serverstorage:WaitForChild("Undead"):Clone()
print("tat")
amount +=1
undead.Parent = workspace
if amount == 6 then
break
end
end
end
wave1()
print("a")
end
From what I can see, I guess that you create a logic of how the zombie walks in one script, but that script is not being cloned into the new zombie that you created later.
local ai = {}
local renderservice = game:GetService("RunService")
function ai.Follow(plr, humrootpart)
task.defer(function()
local hum = script.Parent.Zombie
local hitbox = script.Parent.HitBox
local animator = hum.Animator
local animid_kill = script.ZombieAttack
local animid_killgo = hum:LoadAnimation(animid_kill)
local distance = nil
local debounce2 = false
local direction = nil
local zombieroot = script.Parent.HumanoidRootPart
local debounce = false
local Conn = renderservice.Heartbeat:Connect(function()
local mag = (humrootpart.Position - zombieroot.Position)
distance = mag.Magnitude
direction = mag.Unit
hitbox.Touched:Once(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
hit.Parent.Humanoid:TakeDamage(5)
animid_killgo:Play()
print("works!")
task.wait(1)
debounce = false
end
end
end)
if distance <=100 then
hum:Move(direction)
elseif distance >= 100 then
hum:Move(Vector3.new(math.random(50,50)))
end
end)
plr.Character.Humanoid.Died:Once(function()
Conn:Disconnect()
end)
end
end)
return ai