Script that is supposed to keep player moving with object they are standing on isnt working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am making a game that involves riding a subway train. I was creating a script that would update the player’s HumanoidRootPart’s AssemblyLinearVelocity to the same as the object below.
  2. What is the issue? Include screenshots / videos if possible!
    the issue is that the script does almost the opposite. when the part is barely moving the character would jitter and move around like crazy. All modifications ive attempted have either amplified the effect or just didn’t do anything at all.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is the code.

lp = game:GetService("Players").LocalPlayer
char = lp.Character
while lp.Character == nil do wait() char = lp.Character end
char = lp.Character

while wait() do
	for _,p in pairs(char:GetDescendants()) do
		if p:IsA("BasePart") or p:IsA("MeshPart") then
			if char:FindFirstChild("HumanoidRootPart") then
				local h
				local function onHit(hit)
					if p.Name ~= "HumanoidRootPart" then
						p.AssemblyLinearVelocity =, 0, 0)
					if not char:FindFirstChild(hit.Name, true) then
						char.HumanoidRootPart.AssemblyLinearVelocity += hit.AssemblyLinearVelocity
				h = p.Touched:Connect(onHit)