Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"Humanoid is not a valid member of Model" can anyone help me fix this thing?

Asked by 6 years ago
Edited 6 years ago

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
0
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. User#19524 175 — 6y
0
It shouldn't be script.Parent.Humanoid. It should be game.Players.LocalPlayer.Character.Humanoid GGButNO_RE 61 — 6y
0
If you didn't read the first line it's an NPC. User#19524 175 — 6y

Answer this question