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.
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