Moving a part via the server based on mouse

In a localscript, I am detecting mouse movement and changing a parts position according to the mouse position.

This works and is fine and all.

The problem is- I want to change the position via server… obviously I cannot get the mouse position on a server script, so I have to fire a remote event everytime the mouse moves to the server.

This was laggy, any other ideas on what I can do?

Still need help on this. (charsss)

You get Mouse position by a loop then pass it as a position argument through fireserver()

Fire a Server Event and pass the mouse position as a argument.

(chaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrs)

As I said in the post, this was laggy.
Probably because I was sending a remote event everytime the mouse moved.

Are you trying to make a mouse-dragging system such as that of LumberTycoon2?, in which case I think this popular resource could help you:

Not exactly, you don’t click to move the object.

Its a 2D game where a part with a trail follows ur mouse where u go, it raycasts from the mouse onto a grid part and puts the part position to that everytime Mouse.Move occurs.

I see, In this case then I don’t know what else to possibly recommend that wasnt already recommended to you.

Its different and more responsive than when using the Mouse.Moved event.
perhaps with a task.wait() while loop or binding it to RunService.RenderStepped could work out for you.
As for the lag, there will always be network ping delay to take into account, and thats beyond whats in our control.

It was just noticeably not smooth.

So… don’t use mouse.move and use renderstepped task.wait() is what you are saying, right?

If so, I’ll try that, thank you.

Oh its the smoothness in the change whats concerning you? Like its choppy and bounces from one place to another? in this case instead of setting the part position on the server script, use TweenService to tween the position to the new position, Maybe try doing that with your Mouse.Moved method you already scripted first and see how it works out.

Edit: I recommend trying setting the time of the tween to ~1/60th of a second, i.e TweenInfo.new(1/60) theres default values for the other settings so they aren’t as necessary, also if you end up using the looping method I still recommend using tweens.

2 Likes

Do you know how I’d tween it being a model and using this method?
Slice:SetPrimaryPartCFrame(CFrame.lookAt(Slice.PrimaryPart.Position, Pos)) Slice:MoveTo(Pos)

Slice is the part that is moving. Pos is the position of the raycast the part should move to. The first line is making the Slice part LOOK at the position (because I want rotation to change so its looking at the position its going to), then the second is moving it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.