How to make a moving platform that also moves parts on top of it

In my puzzle game, I have a moving platform. I want it so that when players, or cubes (If it matters, yes they are tagged) are put on top of it, and it is moved, that they move with the platform.

Currently, this is the structure I have in explorer:
image
And this is the code found in the MovingPlatformScript:

local TweenService = game:GetService("TweenService")
local CollectionService = game:GetService("CollectionService")

local platform = script.Parent
local glowingPart : Part = platform.Platform.GlowingPart
local root : Part = platform.Platform.Root

local pointAEvent = platform.GoToPointA
local pointBEvent = platform.GoToPointB

local pointA = platform.Parent.PointA
local pointB = platform.Parent.PointB

pointAEvent.Event:Connect(function()
	local tween = TweenService:Create(root, TweenInfo.new(1, Enum.EasingStyle.Linear), { CFrame = pointA.CFrame + Vector3.new(0, 0.75, 0) })
	tween.Completed:Connect(moveFinished)
	tween:Play()
	moveStart()
end)

pointBEvent.Event:Connect(function()
	local tween = TweenService:Create(root, TweenInfo.new(1, Enum.EasingStyle.Linear), { CFrame = pointB.CFrame + Vector3.new(0, 0.75, 0) })
	tween.Completed:Connect(moveFinished)
	tween:Play()
	moveStart()
end)

function moveStart()
	glowingPart.Color = Color3.new(0, 1, 0)
	script.Move:Play()
end

function moveFinished()
	glowingPart.Color = Color3.new(1, 0, 0)
	script.Move:Stop()
	script.End:Play()
end

When the PointA event is fired, it causes the platform to move towards a point above an invisible part named “PointA”. And vice versa with PointB.
(This is using tweens at the moment.)

But currently, when a player stands on top of it, they slide right off.

I tried testing with BodyPosition, but I found that anything other than players also slides off.

And welding wont working. I’ve already seen plenty of posts warning against this for many reasons, in this scenario, it’s because I want players to still be able to move on top of it.

If I’m using BodyPosition, I don’t want to have to manually add a Humanoid to every cube (although I suppose I could script it) and besides, I have sound effects/glowing brick effect that I want to activate once the tween finishes, and as far as I am concerned I can’t detect once it finishes moving.

I’ve heard about raycasts, but the thought of them sounds very daunting. If this is the way, can anybody break down the code that way I can implement it and understand how it works?

What’s the best/any way to achieve what I want?

I hope I’m not being too picky, if I’m missing anything or need more information, please let me know.

2 Likes

you can use bodygyro and bodyvelocity and script for this will look like this:

parent = script.Parent

left = Vector3.new(-15,0,0)
right = Vector3.new(15,0,0)

while task.wait(2) do
	parent.Velocity = left
	wait(2)
	parent.Velocity = right
end

image1

Settings for BodyGyro and BodyVelocity:
–BodyGyro
D: 10000
MaxTorque: 400000, 400000, 400000
P: 20000

–BodyVelocity
MaxForce: 400000, 400000, 400000
P: 2000
Velocity: 0, 2, 0

1 Like

Just use a PrismaticConstraint which is Physics based. There are also many Posts about this same problem on the forums so try the Search bar up top.
I built this free model a couple months ago for someone who asked the same question:

PlatformModel - Roblox

You can script it to move however you want it to, they just wanted a button that moved it and returned it.
Have fun with it!

2 Likes

Thank you both of you.

Just a question, will parts on top of the platform still move with it?

Thank you so much!

Your solution works well, but unfortunately, any parts on top of it will not move.

The only way I can get the parts to move (as a temporary solution) is to parent them to a model with a Humanoid and then remove it afterwards.

But this feels very hacky, is there a way to get the prismatic constraint to move objects above it (including non-humanoid characters)?

EDIT: It does seem to actually move parts on top of it, but it isn’t very consistent if multiple parts (e.g. a player) is also standing on it. But I think I can make it work, thank you!

The issue with multiple players and Parts is that the Parts and Platform will be controlled by the Server, and players will be controlled by the client. This may cause lag issues if you have a game with a lot of lag already.

1 Like