Moving a part into a specific location

Alright, how would I move a part into a specific location? That’s all.

Example: I want Part A to move whatever direction Part B is, which is 10 studs away.

I tried to work with BodyVelocity, but I don’t know how(?) And I wouldn’t use tween because, I want it to be serversided, to avoid delays from client to server and vice versa, and also lag.

To save you time from thinking of a code, I’m trying to learn Lua, so please do not send scripts for me to copy and paste. I just want to know what should I do to achieve what the title of this thread is.

Thank you in advance for helping me!

You can use their Position attribute to move them. Can you give more context on how you want this to work?

What do you mean to use their position attribute? I want Part A to move (not just teleport, but rather to move like, i want it to see moving) into Part B, thanks for helping!

You can use the :Lerp() property to do that.

1 Like

Try TweenService | Roblox Creator Documentation

1 Like

I would try to avoid tween because, sometimes it is inaccurate and has delays… well that’s atleast what i heard, correct me if im wrong, thank you!

The tween service would be great for this unless you want it to be physics based. It doesn’t have delays or inaccuracy.

I see what you mean, from the topic. You should tween it on the client to avoid that.

1 Like

I’ve just read about lerp, can you tell me how can I use it to make the part move from Location A to Location B? thank you!

responding to what @DiamondKingGuy63 said, the alternative is using RunService. You would need to define how long it takes to get there and your current time position. Increment the time position by the deltaTime provided by the function in RunService. Use CFrame:Lerp to move the part along according to the ratio of currentTime/totalTime. Finally disconnect the event when the object reached the goal.

I don’t use TweenService much but it definitely works and works smoothly.

1 Like

Lerp is basically (exactly) what a tween is. Lerp gets a point some percentage between two points.

If you’re fine with using legacy body movers, you can use a BodyPosition and tween the position property. That will be smooth even if done from the server because it’s physics based so it’s interpolated (smoothed out on the client).

edit: typos

Instructions (server sided code):

  • Create a BodyPosition
  • Set MaxForce to Vector3.one * math.huge
  • Set Position to the part’s position
  • Add it to the part
  • Create a tween for the body position from the current part position to the goal
  • Play the tween
1 Like

the reason why I want to to be serversided, because there would be more than one part that has to be moved, and each part would be treated differently. If it hit a player, it either kills them or damage them, thank you!

2 Likes

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