Zombie script problem

How do i make a script not target a specific player? if if do an if statement to check if the "Temp2.Name isnt the players name, the script stills target that specific player

local larm = script.Parent:FindFirstChild(“HumanoidRootPart”)
local rarm = script.Parent:FindFirstChild(“HumanoidRootPart”)

function findNearestTorso(pos)
local list = game.Workspace:GetChildren()
local torso = nil
local dist = 50
local temp = nil
local human = nil
local temp2 = nil
for _, entity in ipairs(list) do
temp2 = entity
if temp2:IsA(“Model”) and temp2 ~= script.Parent and temp2.Name ~= “ItzVasi” then
temp = temp2:FindFirstChild(“HumanoidRootPart”)
human = temp2:FindFirstChild(“Humanoid”)
if temp and human and human.Health > 0 then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end

while true do
wait(1)
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target then
script.Parent.Zombie:MoveTo(target.Position, target)
end
end

1 Like

You are checking that specific player is not target using condition temp2.Name ~= “ItzVasi”.
To avoid targeting the specific player, you can add an extra check inside the for loop to ignore the “ItzVasi” player completely.

1 Like

I have a modified version of this exact script.

--local larm = script.Parent:FindFirstChild("Left Arm")
--local rarm = script.Parent:FindFirstChild("Right Arm")
--local laser = Instance.new("Part")
--local light = Instance.new("SurfaceLight")
--laser.Name = "laser"
--laser.Material = Enum.Material.Neon
--laser.Color = script.Parent.Parent.Head.Color
--light.Parent = laser
--light.Color = laser.Color
--light.Range = math.huge
--light.Shadows = true
--light.Angle = 180
--light.Face = 0
--for count = 1, 5, 1 do
--	light2 = light:Clone()
--	light2.Face = count
--	light2.Parent = laser
--end
--laser.Anchored = true
--laser.CanCollide = false
local r1i = math.random()*20-10+script.Parent.Parent.HumanoidRootPart.Position.X
local r2i = math.random()*20-10+script.Parent.Parent.HumanoidRootPart.Position.Y
local r3i = math.random()*20-10+script.Parent.Parent.HumanoidRootPart.Position.Z
local tmr = 0
function findNearestTorso(pos)
	local list = game.Workspace:children()
	task.desynchronize()
	local torso = nil
	local dist = 200
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.className == "Model") and (temp2 ~= script.Parent.Parent) then
			task.synchronize()
			temp = temp2:WaitForChild("HumanoidRootPart",0.1)
			human = temp2:WaitForChild("Humanoid",0.1)
			local raycastparam = RaycastParams.new()
			raycastparam.IgnoreWater = true
			raycastparam.FilterType = Enum.RaycastFilterType.Exclude
			raycastparam.RespectCanCollide = true
			raycastparam.FilterDescendantsInstances = {script.Parent.Parent}
			task.desynchronize()
			if temp then
			local ray = workspace:Raycast(pos, temp.Position - pos * 2 + pos, raycastparam)
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and temp.Parent.isinf.Value == false and ray ~= nil then
				local pos2 = pos/2 + ray.Position /2
				task.synchronize()
				--laser.Size = Vector3.new(0.25,0.25,ray.Distance)
				--laser.CFrame = CFrame.lookAt(pos2, temp.Position)
				--laser.Parent = workspace
				task.desynchronize()
				if (temp.Position - pos).magnitude < dist and ray.Instance.Parent == temp.Parent then
					torso = temp
					dist = (temp.Position - pos).magnitude
					local pos2 = pos/2 + ray.Position /2
					task.synchronize()
					--laser.Size = Vector3.new(0.25,0.25,ray.Distance)
					--laser.CFrame = CFrame.lookAt(pos2, temp.Position)
					--laser.Parent = workspace
				end
				end
			end
		end
	end
	return torso
end

while true do
	wait(0.05)
	local r1 = math.random()*20-10
	local r2 = math.random()*20-10
	local r3 = math.random()*20-10
	tmr += 1
	if tmr == 60 then
		tmr = 0
		r1i = r1+script.Parent.Parent.HumanoidRootPart.Position.X
		r2i = r2+script.Parent.Parent.HumanoidRootPart.Position.Y
		r3i = r3+script.Parent.Parent.HumanoidRootPart.Position.Z
	end
	local target = findNearestTorso(script.Parent.Parent.HumanoidRootPart.Position)
	task.synchronize()
	if target ~= nil and script.Parent.Parent.isinf.Value == true then
		script.Parent.Parent.Humanoid:MoveTo(target.Position, target)
	end
	if target == nil and script.Parent.Parent.isinf.Value == true then
		script.Parent.Parent.Humanoid:MoveTo(Vector3.new(r1i,r2i,r3i))
	end
end

I actually have a whole infection system to go with it this is just the zombie chasing script
it should be parented under an actor.
Tell me if you want the other scripts.

1 Like

String comparisons are case-sensitive. ItzVasi is not the same as itzVasi