Is it inefficient? It works for like 2 seconds, and then it is just choppy and laggy. What is causing this?
enabled = false
game.Players.LocalPlayer:GetMouse().Move:connect(function()
if enabled == true then
closestdist = math.huge
for i,v in pairs(workspace:FindFirstChild(game.Players.LocalPlayer.Name.."Tycoon"):FindFirstChild("Grid"):GetChildren()) do
v.Name = i
target = game.Players.LocalPlayer:GetMouse().Hit.p
if (target - v.Position).magnitude < closestdist then
closestgrid = v
print(closestgrid)
closestdist = (target - v.Position).magnitude
x = v.Position.x
y = v.Position.y
z = v.Position.z
end
if object ~=nil then
if enabled == true then
enabled = false
for o=0,1,.2 do wait()
object:SetPrimaryPartCFrame(object:GetPrimaryPartCFrame():lerp((CFrame.new(x,y,z)),o))
end
repeat wait() until object:GetPrimaryPartCFrame() == CFrame.new(x,y,z)
enabled = true
end
--object:MoveTo(Vector3.new(v.Position.x, v.Position.y, v.Position.z))
--objectname = object.Name
--game.ReplicatedStorage.placeitem:FireServer(x,y,z, objectname)
else
print('Grid Pos Failure')
end
end
end
end)

1 comment
Try adding a wait() to the end and see if it works better..