Making a moving platform that moves objects and players

I am trying to make a moving platform that, when there is a player or object on it, the moving platform carries said entity with it, pretty simple.

So far I have a working moving platform with tweens though the code I used to move players was made with a tutorial and I am not exactly sure how it works and or how to make it work with objects and not just players.

The code that allows players to be carried with the platform is shown below:

		RunService.Stepped:Connect(function(_, deltaTime)
			local currentPosition = door.Position
			local deltaposition = currentPosition - lastposition

			local velocity = deltaposition / deltaTime

			door.AssemblyLinearVelocity = velocity

			lastposition = currentPosition

		end)

I have a vague understanding of it but am unsure how to change it to work with objects, any help would be appreciated. I have looked around for a solution but everything I have found only works with players and does not function with objects.

1 Like

Can you explain more of what you mean by objects? Like unanchored parts? Or extra details to the platform?

Unanchored parts. I want the platform to be able to move unanchored parts as well as players.

Unanchored parts should be inheriting the AssemblyLinearVelocity of the part they’re on just like the player, is the code snippet you sent running on the server or the client?

It is server-sided, the platform in question that is being tweened is anchored.

Okay, so I did some testing and it turns out that unanchored parts inheriting AssemblyLinearVelocity is super finicky. Your best bet may be to have the platform check for any touching parts, and if they are one of your unanchored objects, give them the same AssemblyLinearVelocity the platform has.

How am I supposed to tell the velocity from an anchored part? As I stated the platform that moves is anchored and I thought anchored parts had no velocity.

They don’t have velocity yeah, but the code snippet you posted shows that your manually setting its velocity to match what it should be based off of how fast its moving in the tween. So you can use that velocity value elsewhere now.

Like I said I made it with a tutorial and I don’t fully understand how it works, how would I change it to make it function properly?

You can use an unanchored moving platform that uses an AlignPosition to closely follow an invisible tweened object, that way objects on the platform will move with it.

1 Like

What @MooMooManager said would work well, but if you want to remain using a purely anchored platform, then wouldn’t need to modify the tutorials code.
What you’d do is add to the end of that RunService.Stepped connection and perform a overlap check (workspace:GetPartBoundsInBox(Platform.CFrame, Platform.Size + Vector3.one) would return an array of all touching parts, you’d then need to sort through it to find specifically the parts you want to move. Then set their AssemblyLinearVelocity to the Platform.AssemblyLinearVelocity.)

It would get laggy if you had a lot of platforms due to rapid overlap checks, so you could move it to a slower loop if that ends up becoming a problem.


Like this?

1 Like

I am able to create what you are trying to do. But my method may not be the best. because I put the move script in the platform and object.

local part = script.Parent
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, -1, true)

local tween = TweenService:Create(part, tweenInfo, {
	CFrame = part.CFrame * CFrame.new(0,25,0)
})

tween:Play()




local lastPosition = part.Position

RunService.Stepped:Connect(function (_, deltaTime)
	local currentPosition = part.Position
	local deltaPosition = currentPosition - lastPosition
	
	local velocity = deltaPosition / deltaTime
	
	part.AssemblyLinearVelocity = velocity
	
	lastPosition = currentPosition
end)

a short video example. 


![Move|video](upload://dhBk2xFXVkefAdgfKzBMuiserMc.mp4)

Here is the video reuploaded to help with your issue.

This does not seem to work, and using align position/orientation for some reason does not function properly with the parts, I can only seem to get align to work with parts of the default size and I do not understand why, a platform with the same dimensions and properties as the tweened platform (though without scripts) does absolutely nothing. This makes even less sense considering I tried this earlier and it seemed to work, though it would cause parts on the platform to fling and the platform would bugg out extremely badly.

Topic I solved recently, this should help you

Again this only seems to move the player and not physics objects.


Mechanical Constraints
Mover Constraints

Use a Plane Constraint to make the platform float on the desired plane. Then apply the correct Linear Velocity Constraint in the direction to go. I also use an Align Orientation Constraint so that it doesn’t rotate due to any weight or other forces.

Add this script to an object and it will work. It stops quite smoothly and works with all objects that aren’t the Baseplate. You’ll have to add your own filtering for the objects you want if you want a different functionality than that.

Set the platform’s Friction to 1 so that other parts do not slide and fall off easily

local touching = 0
script.Parent.Touched:Connect(function(otherPart)
	if otherPart ~= workspace.Baseplate then
		touching += 1
		script.Parent.Attachment.LinearVelocity.Enabled = true
		script.Parent.Anchored = false
	end
end)

script.Parent.TouchEnded:Connect(function(otherPart)
	if otherPart ~= workspace.Baseplate then
		touching -=1
		if touching <= 0 then
			script.Parent.Anchored = true
			script.Parent.Attachment.LinearVelocity.Enabled = false
		end
	end
end)

I tried this same method with the Align Position Constraint and it did not work as it seemed to apply 0 friction to other parts, so they always fell off. It worked with the player though. This method works with other parts AND the player.