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

how to get zombie to follow closest person?

OK so I have this script and everything looks like it would work, but its doing nothing, there are no errors in the output or anything. the problem is in the findNearestTarget() function, it wont update tar(A Vector3Value). please help!?!?!

local player = script.Parent
local followingPath = false
torso = script.Parent.Torso
range = 500
target = nil

function findNearestTarget()
	for _,plr in pairs(game.Players:GetPlayers()) do
		if plr.Character ~= nil then
			tor = plr.Character.Torso
			if target ~= nil then
				if(torso.Position-tor.Position).magnitude < (torso.Position-target.Torso.Position).magnitude or (torso.Position-tor.Position).magnitude <= range  then
					target = plr.Character
					break
				end
			end
		end
	end
end

while true do
	wait(.1)
	findNearestTarget()
	if target~=nil then
		script.Parent.tar.Value = Vector3.new(target.Torso.Position)
	end
end

while true do

	if not followingPath then
		followingPath = true
	path = game:GetService("PathfindingService"):ComputeRawPathAsync(player.Torso.Position, script.Parent.tar.Value, 500)
	points = path:GetPointCoordinates()
	
	game.Workspace.Points:ClearAllChildren()
	
	for p = 1, #points do
		local part = Instance.new("Part")
		part.Size = Vector3.new(1, 1, 1)
		part.Position = points[p]
		part.Anchored = true
		part.CanCollide = false
		part.Parent = game.Workspace.Points
	end
	
	for _, point in pairs(points) do
		script.Parent.Zombie:MoveTo(point)
		repeat
			distance = (point - player.Torso.Position).magnitude
			wait()
		until distance < 3
	end
	followingPath = false
	end
	wait(0.1)
end



1 answer

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