BodyPosition after a while no longer grips player to moving platform

So I posted not so long ago about how to get a player to stick/grip on a moving platform:

I managed to get it working using BodyPosition and BodyGyro on the moving platform.
Everything seemed to be working…I could move the player on top of a directional arrow button, and that button would move the platform by setting the Position property of the BodyPosition object. I set this on a heartbeat whilst the button is being pressed, e.g.:

local targetVelocity = 5 -- Measured in studs per second.
local targetPosition = platformBodyPosition.Position
for _, direction in ipairs(directions) do
	local offset = (targetVelocity * step) * direction
	targetPosition = targetPosition + offset
end
platformBodyPosition.Position = targetPosition

When I first start moving the platform with the player on it, everything seems good (the player moves with the platform). But after a while I noticed the player slowly stops gripping the platform. The more I moved the platform back and forth with the player, the worse it eventually gets and the player starts falling off the button instead of staying on top of the button (which currently sits on top of the moving platform as shown in the screenshot)

Here are my settings:

local movingPlatform = platform.MovingPlatform
local platformBodyPosition = movingPlatform.BodyPosition
local platformBodyGyro = movingPlatform.BodyGyro

platformBodyPosition.Position = movingPlatform.Position
platformBodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
platformBodyPosition.D = 100
platformBodyPosition.P = 10000

platformBodyGyro.D = 500 
platformBodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
platformBodyGyro.P = 3000 
platformBodyGyro.CFrame = movingPlatform.CFrame

movingPlatform.Anchored = false

So whats causing my player to eventually start to fall of the platform as opposed to moving with it? Like I said it works perfectly to begin with. But then gradually gets worse.

Thanks, really appreciate any help anybody can provide.

1 Like

This has been mentioned before on occasion. I highly recommend you check out the following topic:

However, the topic is relatively old and some methods have changed over time. As such, it is still updated fairly frequently with new scripts. That for for the new methods. Here is one such script:

Thanks. I removed the BodyPosition & BodyGyro stuff. Moved the platform how I originally had it, updating its CFrame. And then used the LocalScript in the post that you linked, placed in the StarterCharacterScripts and it worked well. Thank you.

1 Like