Make a player stick to a part that is being tweened?

Here is the demo game I have been working on: train! - Roblox

I am using TweenService to tween the parts of the train, but the player just slides off the train. How can I make a player move with the train, similarly to JailBreak?

Thank you all so much for your help.

One of the ways you can do this is when the tween plays then you could get the players character and anchor the characters rootpart to the train. That is probably the easiest way.

And how exactly would I go about doing that? Sorry, I just don’t have a clue.

TAKE A LOOK AT THIS THREAD IT HAS THE SAME ISSUE AND THEY SOLVED IT IN SOLUTION LMK IF YOU HAVE QUESTIONS…THX!!!

I gave that thread a try, and the player ended up still gliding off the train.

Yes. I believe that it is not working because there are multiple train carriages and they all have the same name. I am currently experimenting with fixing this…

I can send you the actual place in messages.

IN THE FILE YOU GAVE ME, THE TRACKS WHERE ABOUT THE SAME SIZE AS THE TRAIN.
THIS MADE THE SCRIPT DETECT THE PLAYER AS BEING ON TOP THE TRACK INSTEAD OF THE TRAIN PART.
I MADE THE TRACKS SHORTER TO MAKE THIS NOT HAPPEN.
IT WORKS FINE NOW.

please let me know if you need any more help with the script / want to understand it better.

1 Like

Create a weld constraint between the object being tweened and a part on the character

--tween plays
local wc = Instance.new("WeldConstraint")
wc.Part0 = partThatsBeingTweened
wc.Part1 = character.HumanoidRootPart
wc.Parent = partThatsBeingTweened

This script works if there are multiple parts that has the same name for me:

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 character = player.Character or player.CharacterAdded:Wait()
	local RootPart = character.Torso
	
	local Whitelist = {} -- Table of Every "RaftTop"  (You could just make a model or folder for it.)
	
	local ray = Ray.new(RootPart.CFrame.p,Vector3.new(0,-50,0))
	
	local Hit, Position, Normal, Material = workspace:FindPartOnRayWithWhitelist(ray,Whitelist)

	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)