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
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.
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.
01 | local torso = script.Parent.Torso |
02 | local h = script.Parent.Humanoid |
03 | local spawnCF = script.Parent.Torso.CFrame |
04 |
05 | function findPlayer() for _,v in next , game.Players:GetPlayers() do |
06 | if v.Character then |
07 | local char = v.Character |
08 | if char:FindFirstChild( "Humanoid" ) and |
09 | char:FindFirstChild( "Torso" ) then |
10 | local ptorso = char.Torso |
11 | if (ptorso.Position - torso.Position).magnitude < = |
12 | 30 then return v |
13 | end |
14 | end |
15 | end |