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

Why dosen't my enemy follow nor move at all?

Asked by 6 years ago

local torso = script.Parent.Torso local h = script.Parent.Humanoid local spawnCF = script.Parent.Torso.CFRAME

function findPlaayer() 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 <= 30 then return v
end end end end end return nil

while wait()do local player = findPlayer() if player ~= nil then h:MoveTo(player.Character.Torso.Position) else h:MoveTo(spawnCF.p) end end

0
Probably just a typo. You set the variable for your function to findPlaayer() and then called it using findPlayer() Are you getting any errors in the output? protectiveebob 221 — 6y
1
this is the error workspace.STONEGUARD.Follow:20:'<eof>' expected near 'while' Amier3tears 1 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago

You spelled 'Player' wrong in the code 'function findPlaayer() for _...'. If that didn't work make sure it is unanchored and welded properly. If the problem was the typo, don't accept this answer as it was protectiveebob who said that first in the comments.

Ad
Log in to vote
0
Answered by 6 years ago

Let me know if it doesn't work, I got a couple other tricks I could try. Tip: you can format your post to display code by highlighting all the pasted code and pressing the little blue Lua button. And you had an extra "end". Use tabbing to keep track of them.

local torso = script.Parent.Torso
local h = script.Parent.Humanoid 
local spawnCF = script.Parent.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 <= 
            30 then return v
         end
      end
   end 
return nil
end 


while wait() do 
   local player = findPlayer()
   if player ~= nil then 
      h :MoveTo(player.Character.Torso.Position) 
   else
      h:MoveTo(spawnCF.p)
   end
end

Answer this question