How do I fixed this laggy script, Am I not using loops correctly?
Is it inefficient? It works for like 2 seconds, and then it is just choppy and laggy. What is causing this?
02 | game.Players.LocalPlayer:GetMouse().Move:connect( function () |
03 | if enabled = = true then |
04 | closestdist = math.huge |
05 | for i,v in pairs (workspace:FindFirstChild(game.Players.LocalPlayer.Name.. "Tycoon" ):FindFirstChild( "Grid" ):GetChildren()) do |
07 | target = game.Players.LocalPlayer:GetMouse().Hit.p |
08 | if (target - v.Position).magnitude < closestdist then |
11 | closestdist = (target - v.Position).magnitude |
17 | if enabled = = true then |
20 | for o = 0 , 1 ,. 2 do wait() |
21 | object:SetPrimaryPartCFrame(object:GetPrimaryPartCFrame():lerp((CFrame.new(x,y,z)),o)) |
23 | repeat wait() until object:GetPrimaryPartCFrame() = = CFrame.new(x,y,z) |
30 | print ( 'Grid Pos Failure' ) |