Hello this is a script from Jailbreak train platform system? - #35 by Kord_K
Problem
The problem is that the code will only work if the part is called “RaftTop”
But what I want instead of making all parts name “RaftTop” I want it to work in models.
Script This script allows player to jump and walk in a moving Cframe 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 == “RaftTop” 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()
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)
end)