Trying to make the player follow a moving platform that is using TweenService

Hello, I got a moving platform that is using TweenService, to make the player follow it I tried to use this local script that updates the player’s CFrame if he stands on the platform:

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')

local LastTrainCFrame

local Function
local Function2


Function = RunService.Heartbeat:Connect(function()

	--------------------------------------------------------------- CHECK PLATFORM BELOW

	local RootPart = player.Character.LowerTorso

	local Ignore = player.Character

	local ray = Ray.new(RootPart.CFrame.p,Vector3.new(0,-50,0))

	local Hit, Position, Normal, Material = workspace:FindPartOnRay(ray,Ignore)

	if Hit and Hit.Name == "TrainPlateform" then -- Change "RaftTop" to whatever the moving part's name is

		--------------------------------------------------------------- MOVE PLAYER TO NEW POSITON FROM OLD POSITION

		local Train = Hit
		if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
			LastTrainCFrame = Train.CFrame -- This is updated later.
		end
		local TrainCF = Train.CFrame 

		local Rel = TrainCF * LastTrainCFrame:inverse()
        print(Rel)
		LastTrainCFrame = Train.CFrame -- Updated here.

		RootPart.CFrame = Rel * RootPart.CFrame -- Set the player's CFrame
		--print("set")

	else
		LastTrainCFrame = nil -- Clear the value when the player gets off.

	end

	Function2 = player.Character.Humanoid.Died:Connect(function()
		Function:Disconnect() -- Stop memory leaks
		Function2:Disconnect() -- Stop memory leaks
	end)
wait()
end)

but when I run the game this happens:

is there a way to fix this?

2 Likes

You could just use BodyVelocity and other body movers to move the platform, this way Roblox Physics is used, and it automatically moves the player.

1 Like

yes but there is one problem this platform doesn’t just go in one direction it takes turns, like it follows multiple parts placed along the rails
and I think that body movers wouldn’t be as smooth as tween service

Then you can change the body velocity when it is taking a turn

1 Like

sorry but I really want it to move using tween service so that I can set more easily the way it moves

Before telling you what the problem is, I wanted to point out that workspace:FindPartOnRay is deprecated. Switch to workspace:Raycast() instead.

Anyways, I don’t think that setting the RootPart’s CFrame is ideal. You can make it ideal, but it will take quite a bit of calculations to do so. Instead, set the AssemblyLinearVelocity of the platform to the speed/direction it’s heading. This will create a seamless experience for the player (especially since it’s a LocalScript).

5 Likes

okay, I’ll try to do that, I’ll tell you later if it worked or not

1 Like

yes I’ve already seen that topic I’m even using their local script but for some reason when I try it with the tween service moving platform it keeps teleporting the player to the front of the platform

1 Like

Oh… haha my bad, my fault I didn’t see the post correctly. I’ll look it

1 Like

Have you tried using the roblox built-in walking platforming system?

For me the jailbreak system worked well

what do you mean, what is that?

1 Like

mm got one question does this use physics?

1 Like

the method I used uses physics for moving the player but the part uses tween service

I do not have the solution but here’s 2 ideas that I’ve gotten:

  1. Are you able to obtain the force vectors applied on the moving part? If there is a way to obtain it, perhaps you could somehow apply that force onto the players character.

  2. You can attempt to change the frictional force value of the surfaces which may help the character stay on the platform (I doubt this will work)