Most Efficient Moving Platform?

Hey, I’d like to create a moving platform. It’s a fairly straightforward process. I found Roblox’s official tutorial on YouTube and this is what they propose:

local Platform = script.Parent
local BodyPosition = Platform.BodyPosition

local Part0 = workspace.Part0 
local Part1 = workspace.Part1

local WaitTime = 5

while true do
    BodyPosition.Position = Part0.Position
    wait(WaitTime)
    BodyPosition.Position = Part1.Position
    wait(WaitTime)
end

This tutorial was from 2014. I’m wondering if there is a better way to do this now.

Would it be better to use a :Changed event to check if the platform’s position has moved close enough to its target position, wait some time, then change the target position again? I’m worried that having multiple moving platforms and having a while true do loop for each one would cause lots of lag. I also think it’d be more reliable to check the platform has reached the target rather than using wait() because I want to be able to create multiple moving platforms and not have to determine the wait time through trial and error.

1 Like

Do players have to be able to stand on it? If not, you could use cframe animation or tweening. If you need players to stand on it, it can get complicated. You’ll have to use some sort of physics constraint or else do some creative coding. Prismatic constraint works fairly well for this for moving a part with players on it.

Hey! It’s kinda funny that I meant to link your thread here earlier. Did you figure out the best practices? :smiley: 2021 Moving Platforms are there any new best practices?

I think I’ll go with prismatic constraints but how do I decide when to change its target position? With a while true do loop like above or a :Changed event?

No, but I settled on prismatic constraint. haha :slight_smile: There is a slight jitter when viewing other characters riding on the same platform, unless they sit in a seat.

Here is a good example ‘place’ that you can edit to see how it works. This one has a platform that goes back and forth from one start part to a finish part.

It works best if you only need the part to go in the same path over and over (like an elevator)

2 Likes

Cool. It’s using the method I started off using which is to check using .Touched events. I think that’s the most efficient way. I like that it checks both if the object touching is the moving platform AND it depends on a bool value so that it’s very secure.

Thanks! :slight_smile: