I attempted to create a Zombie Script where the Zombie follows you and kill you. I made a huge attempt of Scripting the Zombie to follow you but I could not figure out how to get it to kill you. I desperately need assistance on both of those. Below is what I attempted to Script:

local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
distance = script.Parent.Configuration.distance.Value 

function findNearestTorso(pos)
	local list = game.Workspace:children()
	local torso = nil
	local dist = distance 
	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) then
			temp = temp2:findFirstChild("Right Arm")
			human = temp2:findFirstChild("Humanoid")
			if (temp ~= nil) and (human ~= nil) 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(math.random(1,1))
	local target = findNearestTorso(script.Parent.Torso.Position)
	if target ~= nil then
		script.Parent.Humanoid:MoveTo(target.Position, target)
	end

end

8 comments

0

code block pls

0

Edited to add code block.

0

<3

0

Sorry, it is difficult to add. I am new here!

1

In the future -- select all of your code, and press the Lua button above the text box. A line of ~~~ will appear before and after the code.

0

Thanks.

0

Why are you doing 'wait(math.random(1, 1))

0

I forget. I was trying to make it work for a very long time and I was getting very stressed and depressed.