Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a moving platform that moves back and forth at a constant velocity?

Asked by 3 years ago

Hi! This is my second post on Scripting Helpers. Sorry if I do anything wrong. So, there is a "Start" part, and a "Stop" part. There is also a "MP" (Moving Platform(or part)) part. The MP has a BodyVelocity, that is set to -16 in the X direction until it has the same position as the Start. Then, it will wait for a few seconds and set its velocity will now be set to 16 in the positive X direction. Then it will wait a few seconds again. All the parts are in a model named MM1. (It does not matter what it stands for). This zig zag is in a "while true" loop, so the process will repeat forever , But everytime I run it, the platform falls off. And when I anchor it, it does not move. This is the code I used.

local start = game.Workspace.MM1.S1
local mp = game.Workspace.MM1.MP
local vel = game.Workspace.MM1.MP.BodyVelocity
local stop = game.Workspace.MM1.E1

while true do
    while mp.Position ~= start.Position do
        vel.Velocity = Vector3.new(-16,0,0)
    end
    wait(2)
    while mp.Position ~= stop.Position do
        vel.Velocity = Vector3.new(16,0,0)
    end
    wait(2)
end

Can someone help me please?

Answer this question