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

My Follow Script isnt working on real Roblox but on Studio, But it has no errors ?

I don't know why. My Follow script wont work on Roblox, It does in studio but not in real Roblox can you help? The Zombie I made should follow the closest player, but it in studio is works but on Roblox they just stand still

local humanoid = script.Parent.Zombie
local Torso = script.Parent.Torso
local MaxDistance = 999999999999

function MoveTowardsAPerson(pos)
	local People = {}
	local MoveTo
	for i,v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") and v:findFirstChild("Humanoid") then
			if game.Players:GetPlayerFromCharacter(v) then
				table.insert(People,v)
			end
		end
	end
	
	for i,v in pairs(People) do
		local pos2 = v.Torso.Position
		local mag = (pos - pos2).magnitude
		
		if mag <= MaxDistance and game.Players:FindFirstChild(v.Name).CanFollow.Value == true then
			MoveTo = v.Torso
		end
	end
	
	if MoveTo ~= nil then
		return MoveTo
	end
end

while game:GetService("RunService").RenderStepped:wait() do
	if humanoid.Health > 1 then
		local t = MoveTowardsAPerson(Torso.Position)
		if t ~= nil then
			humanoid:MoveTo(t.Position)
		end
	end
end

2 comments

0

Perhaps try adding a wait at the beginning?

1 answer

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