More than one zombie does not work

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

Post your code chars chars chars

2 Likes

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.

I swear I posted my code I don’t know what happened to it

Posted itㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

Is anybody able to help?ㅤㅤㅤㅤㅤㅤ

Can you also post the Explorer panel inside the studio of where your zombies are, and where this code has been placed in?

The code works and is placed in ServerScriptService
The zombies are in ServerStorage

Any helpers? ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

Please let me see how you structured your zombies inside the Explorer panel

oh hey its you again.

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
2 Likes

This is how they are structured
image

Same behaviour when pasted unfortunately

I’m honestly confused, the zombies still have a script and the script is running every single line yet the zombies don’t move

Alright works in Roblox client and I do not know why
Can somebody explain why it didn’t work in Roblox studio but works in Roblox client?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.