Im Planning to make an Npc to follow me but i somehow can't. How is this happening?
local h = script.Parent.Humanoid
local torso = script.Parent.Torso
local spawnCF = torso.CFrame
function findPlayer()
for _,v in next, game.Players:GetPlayers() do
if v.Character then local char = v.Character
if char:FindFirstChild("Humanoid") and char:FindFirstChild("Torso") then
local ptorso = char.Torso
if (ptorso.Position - torso.Position).magnitude <= 20 then
return v
end
end
end
end
return nil
end
while wait() do
local player = findPlayer()
if player ~= nil then
h.WalkToPoint = player.Character.Torso.Position
else
h.WalkToPoint = spawnCF.p
end
end

3 comments
Don't use wait() as a condition, and it didn't work because a Humanoid wasn't found. Also put your code in a code block.
It shouldn't be script.Parent.Humanoid. It should be game.Players.LocalPlayer.Character.Humanoid
If you didn't read the first line it's an NPC.