Bot Script Error

I’m following a scripting tutorial and the script isn’t working. This is all it says in the output and I don’t know what to do

here’s the script:

local zombieHumanoid = script.Parent.Humanoid

local function findTarget()
	local agroDistance = 100
	local target = nil
	for i, v in pairs(game.Workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso")
		if human and torso and v ~= script.Parent then
			--Check distance
			if (zombieTorso.Position - torso.Position).magnitude < agroDistance then
				agroDistance = (zombieTorso.Position - torso.Position).magnitude
				target = torso
			end
		end
	end
	return target
end
while wait(1) do 
	local torso = findTarget()
	if torso then
		zombieTorso:MoveTo(torso.Position)
	end
end
3 Likes

You need to use MoveTo() on a Humanoid not the Torso which is a part.

I’ve tried setting it to humanoid but nothing different has happend

Replace zombieTorso:MoveTo(torso.Position) with zombieHumanoid:MoveTo(torso.Position). Also make sure the rig isn’t anchored.

It makes sense and I tried it out but it didn’t work. :confused: I was confident it was going to work too T_T

What does it do now?

Put a print.

I don’t see where you have defined: zombieTorso, but I may be blind.

You do not move humanoids. MoveTo() works on models.

There are two dif MoveTo s…

This Humanoid def moves. Mod it.

AI - Roblox

local zombieHumanoid: Humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
if not zombieHumanoid then
   print("The humanoid doesn't exist. This script will create one now.")
   zombieHumanoid = Instance.new("Humanoid")
   zombieHumanoid.Parent = script.Parent
end

local function findTarget()
	local agroDistance = 100
	local target = nil
	for i, v in pairs(game.Workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso")
		if human and torso and v ~= script.Parent then
			--Check distance
			if (zombieTorso.Position - torso.Position).magnitude < agroDistance then
				agroDistance = (zombieTorso.Position - torso.Position).magnitude
				target = torso
			end
		end
	end
	return target
end
while task.wait(1) do 
	local torso = findTarget()
	if torso then
		zombieHumanoid:MoveTo(torso.Position)
	end
end

Let me know if this works! I basically added detection for if there is no Humanoid inside of the zombie yet. If no Humanoid is found, it will create one then.

I defined zombie torso at the top in the actual script but it cut out on the forum for some reason. I tried out the print and torso and it didn’t work T_T

I tried it out on a r6 character in game and it worked! Then I tried it out in game and it didn’t follow. After I tried it out on a r16 character and it didn’t work. It works on r6 characters but not r16 characters. (I also changed the torso to human root part and it still didn’t work)

WAIT NVM I fixed it in the wrong script thank you for helping!!

I transferred the script to another zombie model and it doesn’t work again T_T

last time I say nvm this is getting ridiculous. I fixed it again

Hi! Do you get any errors or anything coming from the output console with my solution?

1 Like

Nope! I just checked the output

1 Like