Jailbreak train platform system?

Hi, I just tried to apply this with a ship, with a whitelist for the ray.

If I don’t move on the ship while the ship is moving, I start sliding towards the front. Any way to fix this?

Here is my code:

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()
	
	local RootPart = player.Character.Torso
	
	local ray = Ray.new(RootPart.CFrame.p,Vector3.new(0,-50,0))
	
	local WhiteList = {workspace.Orion["Cruiser Kappa"]["Cruiser Kappa"].Ship.MovingPart}
	
	local Hit, Position, Normal, Material = workspace:FindPartOnRayWithWhitelist(ray,WhiteList)
	
	if Hit and Hit.Name == "MovingPart" then
		
		local Train = Hit
		if LastTrainCFrame == nil then
			LastTrainCFrame = Train.CFrame
		end
		local TrainCF = Train.CFrame 
		
		local Rel = TrainCF * LastTrainCFrame:inverse()
		
		LastTrainCFrame = Train.CFrame
		
		RootPart.CFrame = Rel * RootPart.CFrame
		
	else
		LastTrainCFrame = nil
		
	end
	
	Function2 = player.Character.Humanoid.Died:Connect(function()
		Function:Disconnect()
		Function2:Disconnect()
	end)
	
end)
1 Like