So, in this script it is supposed to locate the closest grid square to the mouse's position. But, the model goes to like 5 other grid squares before it arrives at the right one. How do I get it to immediately move to the closest grid square?
game.ReplicatedStorage.startmove.OnClientEvent:connect(function(movepart)
object = workspace:FindFirstChild(game.Players.LocalPlayer.Name.."Tycoon"):FindFirstChild(movepart)
enabled = true
end)
game.Players.LocalPlayer:GetMouse().Move:connect(function()
closestdist = math.huge
print(enabled)
if enabled == true then
print('top')
for i,v in ipairs(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
closestdist = (target - v.Position).magnitude
closestgrid = v
print(closestgrid)
x = v.Position.x
y = v.Position.y
z = v.Position.z
print('middle')
if object ~=nil then
enabled = true
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(.1) until object:GetPrimaryPartCFrame() == CFrame.new(x,y,z)
enabled = true
print(enabled)
end
else
print('Grid Pos Failure')
end
end
end
end
end)

1 comment
If possible, do this all on the client? Remotes = latency isses.