How can i make a part move locally that uses body position to move?

I’m trying to make a platformer in which I need moving parts that can move the player with them but I also need it to be done locally, to reduce lag. I have a local script that uses body position to move the part and also move the player with it but the body position doesn’t work as it would in a normal script, I put the local script in starterplayerscripts. how would I go about making the local script function as a normal script would? also when I say the local script does not function properly I mean that the body position doesn’t work unless the player is touching the part the body position is inside of.

1 Like

I believe you’ll have to also create the Part in order to simulate it’s local physics that are in relation with the client, it should be something like this:

local Part = PartHere:Clone()
Part.Parent = workspace

local BodyPos = Instance.new("BodyPosition")
BodyPos.Parent = Part

I don’t understand are u saying I have to create te part in the script or make a new part

Create both the Part & BodyPosition in the LocalScript, is what I’m basically saying

If the Part was already inside the workspace, then BodyMover objects (Such as BodyVelocity, BodyPosition, etc) can’t used to move that Part from the client, as the Part is a Server object

1 Like

Hello!

I have found a cool way around it.

Here’s the example of the platform I have in my place. The red part is called ‘Thing’ and it is located in the workspace. Pretty much the idea of it is that it starts at position one and moves two position two to have the player to access the next stage.

The one problem is that this part specifically is made on the server side, since you turned it into a LocalScript, it is now being handled on the client side. Due to filtering enabled, this will not replicate any physics due to the platform’s physics being handled on the server. This is pretty much what @JackscarIitt specified in his reply.

I do have a fix around that by just replacing the specified platform from the server to the client and just using that instead so it can simulate physics.

Here’s the code below, I had the LocalScript inside StarterPlayerScripts and it’s commented if you’d like to configure or fork with the example.

local positionStart = Vector3.new(-18.76, 8.935, -36.049) --> Where the platform starts
local positionEnd = Vector3.new(24.261, 8.935, -36.049) --> Where the platform ends
local serverPlatform = workspace:WaitForChild("Thing") --> This would be the object that is moving.

--# Re-creates the platform, but on the client so we can manipulate it.
local platform = serverPlatform:Clone()
platform.Parent = serverPlatform.Parent
serverPlatform:Destroy()

local bodyMover = Instance.new("BodyPosition")
bodyMover.Parent = platform
bodyMover.P = 1000 -- How agressive the BodyPosition is
bodyMover.D = 1000 -- The acceleration of the BodyPosition
bodyMover.MaxForce = Vector3.new(400000, 400000, 400000)
bodyMover.Position = positionStart

--# This keeps the object from turning at all.
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = platform
bodyGyro.P = 400
bodyGyro.D = 6400
bodyGyro.MaxTorque = Vector3.new(400000, 400000, 400000)

--# As the example given, we made the platform move between two positions.
--# It takes 10 seconds per movement.
while task.wait(10) do
	bodyMover.Position = positionEnd
	task.wait(10)
	bodyMover.Position = positionStart
end

459a128e43c04567b72c4eb9a165baaa (1)

It should work just like a charm! Make sure to mark the post as solution if it helped you :grinning_face_with_smiling_eyes:

4 Likes

Thanks for the reply but, I wanted to make it so that the part moves constantly back and forth to make it a precision jump and Jackscarlett’s method works for that.