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

Follow Script does not work randomly.. Please help a guy out? :c

local	Zombie = script.Parent
local	zombieoid = Zombie.Zombie
local	spawnpos = Zombie.Torso.Position
local	configs = Zombie.Parent.Configurations

function jump(h)
local	player = h.Parent:FindFirstChild("Humanoid")
local	zombie = h.Parent:FindFirstChild("Zombie")
		if not player and not zombie and not h.Parent.ClassName == "Tool" and h.Name~="Bullet" then
			zombieoid.Jump = true
		end
end

Zombie.Torso.Touched:connect(function(hit)
	jump(hit)
end)

function GetClosest(directory,root)
local	tether,closest = configs.FollowDistance.Value ,nil
		for _,part in next,directory:GetChildren() do
			if workspace:FindFirstChild(part.Name) then
		local	dist = (part.Character.HumanoidRootPart.Position-root.Position).magnitude
				if dist < tether then
					closest = part
					tether = dist
				end
			end
		end
		return tether,closest
end

while wait(0) do
	if not Zombie:FindFirstChild("Head") then return end
local	dist,object = GetClosest(game.Players,Zombie.Head)
		if object then
	local	char = object.Character
			if char then
				if char.Humanoid.Health > 0 then
					zombieoid:MoveTo(char.HumanoidRootPart.Position)
					if dist < configs.DamageDistance.Value then
						char.Humanoid:TakeDamage(configs.Damage.Value)
					end
				else
					zombieoid:MoveTo(Zombie.Torso.Position)
				end
			end
		else
			zombieoid:MoveTo(Zombie.Torso.Position)
		end
end

Honestly if you think there is a better Follow script then that, share it as well. ;/ Wouldn't mind.

1 answer

In your script you said if not player and not zombie. That means it won’t follow the player no matter what (this error is inside the function “jump”.

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