Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my NPC not moving at all when the player is in the area?[SOLVED]

I'm trying to make an NPC move only if the character is within 10 studs of the NPC using magnitude and if it isn't then for it to wait until the player is within 10 studs. Any help? Here is my script.

for i,v in pairs(game.Players:GetChildren()) do
	if v and v.Character then
		local distance = 10
		while true do
		wait()
		if (script.Parent.UpperTorso.Position - v.Character.UpperTorso.Position).magnitude <= distance then
		script.Parent.Humanoid:MoveTo(v.Character.UpperTorso.Position)
	else
		repeat wait() until (script.Parent.UpperTorso.Position - v.Character.UpperTorso.Position).magnitude <= distance 
			end
		end
	end
end

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.