Player to Platform Lock System

Hey everyone!

I am attempting to create a “Platform Lock” system for my future games. My goal is to be able to keep a player walking around and jumping while on a platform that moves via TweenService.
This system will be used for:

  • Trains with multiple carriages (Similar to Jailbreak)
  • Elevators
  • Other moving objects

I currently have two issues. The first is not as important as the second since I am prioritizing

So far I have looked through 3 solutions

  1. I tried using the method in the solution of this post, It worked for everything other than the issues stated this is also my current method.

  2. I tried using EgoMooses WallStick modules, even though it works remarkably, it has too many features I do not want. I attempted to make a simpler version that only applies to the floor similar to the previous approach however I am not that advanced at scripting and had no clue what to do

  3. I have looked through a few other posts on dev forum, but none of them were specific enough to my requirements

function onHeartBeat(): ()
	if HumanoidRoot:IsDescendantOf(game) then
		local Result: RaycastResult = workspace:Spherecast(HumanoidRoot.Position, 1, DOWN_VECTOR, PlatformRayParams)

		if Result and Result.Instance and Result.Instance:IsA("BasePart") and Humanoid.Sit == false then
			local Instance_Current: BasePart = Result.Instance
			local CFrame_Current: CFrame = Instance_Current.CFrame

			if ClientStorage.CFrame_Previous == nil or ClientStorage.Instance_Previous ~= Result.Instance then
				ClientStorage.CFrame_Previous = CFrame_Current
			end

			local Rel: CFrame = CFrame_Current * (ClientStorage.CFrame_Previous :: CFrame):Inverse()

			ClientStorage.Instance_Previous = Result.Instance
			ClientStorage.CFrame_Previous = CFrame_Current
			HumanoidRoot.CFrame = Rel * HumanoidRoot.CFrame
		else 
			ClientStorage.Instance_Previous = nil
			ClientStorage.CFrame_Previous = nil
		end
	end
end

Any help is much appreciated, If there is a way to improve my current script to meet my requirements that would be great!

Best, BusinessX

2 Likes