Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fixed this laggy script, Am I not using loops correctly?

Asked by 7 years ago

Is it inefficient? It works for like 2 seconds, and then it is just choppy and laggy. What is causing this?

01enabled = false
02game.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
06        v.Name = i
07    target = game.Players.LocalPlayer:GetMouse().Hit.p
08    if (target - v.Position).magnitude < closestdist then
09        closestgrid = v
10        print(closestgrid)
11        closestdist = (target - v.Position).magnitude
12    x = v.Position.x
13    y = v.Position.y
14    z = v.Position.z
15    end
View all 34 lines...
0
Try adding a wait() to the end and see if it works better.. 4D_X 118 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

bump!

Ad

Answer this question