Hey! Sorry for the late response.
Indeed, transferring the network ownership back is a tedious process. in the version of the script I supplied I said to check if the mouse is no longer moving, and good job deciding to use BasePart.Velocity
for that! Yes, it has been (very) recently deprecated, replaced by :GetVelocityAtPosition()
(I think you need to pass the position of the dragged part as an argument). Constantly checking if the velocity is equal to the zero vector Vector3.new(0, 0, 0)
, and if so proceed to give back ownership to the server.
In the supplied script, for some reason I was too lazy to do this, and instead I put a wait
. This is super bad, if I drag the part again while the wait
still didn’t finish yielding, the ownership will be transferred back mid-dragging, and if I stop dragging the ownership will be transferred to the player now. Chaos!
But even with the velocity check, perhaps that isn’t so perfect. I can think of scenarios where some difficulties may occur. For example, if you stop dragging the part and it drops on a conveyor belt, the part will still have a velocity, hence the ownership is not transferred unless the part is no longer on the belt.
I ended up making an even better version of the script for a project of mine, where I ditched this velocity idea, and very simply decided to constantly check if the mouse is no longer within a certain distance of the character (of course this distance is way greater than the distance of the dragged object from the head). With a bit of fast spawning, this works wonderfully and is way simpler!
I will add this newer version to the article in a second. (too lazy to comment, sorry!)
even_better_dragging.rbxl (31.4 KB)
except that mouse module of yours, oh my
and yes, this uses some magical fancy wrapping shenanings hehe. Here is a page about it, don’t really think about it too much, I only incorporated it due to the suppression of the PlayerMouse.