I made this code to make a enemy follow you when you get near, but it keeps calculating the distance without stopping, and i was wondering if there is a some way to do it run only when the player is close
local player = game.Players.LocalPlayer local enemy = workspace.enemy while true do local dist = (workspace:WaitForChild(player.Name):WaitForChild("HumanoidRootPart").Position - enemy.HumanoidRootPart.Position).magnitude wait(.5) if dist < 30 then enemy.Humanoid.WalkToPoint = workspace:WaitForChild(player.Name).HumanoidRootPart.Position end end