Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make a zombie go to the player with Humanoid:MoveTo() ?

I was following with a tutorial from TheDevKing on Magnitude. Here is the code:


local ZombieRoot = script.Parent.HumanoidRootPart
local ZombieHumanoid = script.Parent.Humanoid

local function findTarget()
	local agroDistance = 100
	for i, v in pairs(game.Workspace:GetChildren()) do
		local Root = v:FindFirstChild("HumanoidRootPart")
		local Humanoid = v:FindFirstChild("Humanoid")
		
		if Root and Humanoid and v ~= nil then
			if (ZombieRoot.Position - Root.Position).Magnitude < agroDistance then
				target = v
			end
		end
	end
	return target
end

while wait(1) do
	local Target = findTarget()
	
	if Target ~= nil then
		print("Found Target!")
		ZombieHumanoid:MoveTo(target.HumanoidRootPart.Position)
	end
end

There are no errors, but for some reason the zombie does not move to the target.

I also put two characters right beside the zombie to see if it would run the print function and it did but for some reason it did not move to the character.

I'm not sure if something else in my script is wrong or I used the Humanoid:MoveTo() function incorrectly. Please help me out if you what's wrong with my script. Thanks!

1 answer

I found a solution but it wasn't really obvious. Instead of using the load character plugin, I just went to the tool box and used a free NPC model. I'm not really sure how it made a difference but for some reason it worked.

This discussion is preserved as it was. New answers, comments, and votes are closed.