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

Why is the model moving everywhere before it comes to the right spot?

Asked by 7 years ago

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?

01game.ReplicatedStorage.startmove.OnClientEvent:connect(function(movepart)
02object = workspace:FindFirstChild(game.Players.LocalPlayer.Name.."Tycoon"):FindFirstChild(movepart)
03enabled = true 
04end)
05game.Players.LocalPlayer:GetMouse().Move:connect(function()
06    closestdist = math.huge
07    print(enabled)
08    if enabled == true then
09        print('top')
10    for i,v in ipairs(workspace:FindFirstChild(game.Players.LocalPlayer.Name.."Tycoon"):FindFirstChild("Grid"):GetChildren()) do
11        v.Name = i
12    target = game.Players.LocalPlayer:GetMouse().Hit.p
13    if (target - v.Position).magnitude < closestdist then
14        closestdist = (target - v.Position).magnitude
15        closestgrid = v
View all 38 lines...
0
If possible, do this all on the client? Remotes = latency isses. Goulstem 8144 — 7y

1 answer

Log in to vote
0
Answered by 6 years ago

I recommend that you do all the moving around on the client so as to create less latency and don't max out the remotes limit. Then when it comes time to create the object or whatever it is into the workspace, use a remote event/function (whatever you deem best) to create that item. Then you will be saving a ton of bandwidth and causing the client less lag. Hope this helps and have a great day scripting!

Ad

Answer this question