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
Perhaps try adding a wait at the beginning?
https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online