Making a player move while standing on a moving part

So I am creating a moving part that moves back and fourth via tweens. I want to know how to make it so if a player stands on top of the platform the player moves with it. Perhaps a velocity calculation or weld.

The platform: https://gyazo.com/cf6eae1b5ea6b9bc29e649495571c5e2

Thanks,

1 Like

You can use a prismatic constraint instead of tweens. I have a model, but I’m unable to provide it to you.

The problem is you are using a tween to move a part, so no game physics are calculated and parts resting on top don’t know how to react. You need to use a body mover or a constraint. Here is an example. Paste this into a new workspace as a Server Script.

local part1 = Instance.new("Part")
part1.Anchored = true
part1.Position = Vector3.new(3, 0.5, -21)
local attachment = Instance.new("Attachment")
attachment.Position = Vector3.new(0,0,-1)
attachment.Parent = part1
part1.Parent = game.Workspace

local part2 = Instance.new("Part")
part2.Anchored = false
part2.Position = Vector3.new(4, 0.5, -25)
part2.Size = Vector3.new(8, 1, 6)
local attachment2 = Instance.new("Attachment")
attachment2.Position = Vector3.new(0, 0, 3)
attachment2.Parent = part2

local constraint = Instance.new("PrismaticConstraint")
constraint.Attachment0 = part2.Attachment
constraint.Attachment1 = part1.Attachment
constraint.ActuatorType = Enum.ActuatorType.Motor
constraint.LimitsEnabled = true
constraint.LowerLimit = -15
constraint.UpperLimit = 15
constraint.MotorMaxForce = 10000
constraint.Velocity = 10
constraint.Parent = part2

part2.Parent = game.Workspace

while true do
	if constraint.CurrentPosition >= constraint.UpperLimit then
		local temp = constraint.Attachment0
		constraint.Attachment0 = constraint.Attachment1
		constraint.Attachment1 = temp
		wait(1)
	end
	wait(0.1)
end
5 Likes
2 Likes

Most definitely! I will look into this method, thanks a lot.

I meant that he should create a prismatic constraint(prior to running) , and then simply alternate from point A to B (Upper to Lower limits)

Yeah, I was able to figure out the whole constraint thingy and have it set up so when it touches certain bricks it will go in a different direction making a back and fourth motion. Thanks for your recommendations.

1 Like