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

How do i create a back and forth moving brick?

Asked by 6 years ago

this is all i got so far:

local Charge = 0

for Charge = 0, 20, 1 do
    script.Parent.Position = script.Parent.Position + Vector3.new(0, 0.1, 0)
    wait(0.01)
end

but it just makes it go up by .2 studs. how do i make a continuous motion?

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

May not be consistent, but it works:

x = 0
y = 1
while y == 1 do -- just so it infinitely loops
    if x == 0 then 
        for x = 0, 20, 1 do
            script.Parent.Position = script.Parent.Position + Vector3.new(0, 0.1, 0)
        wait(0.01) -- so it doesn't crash
    if x == 20 then
        for x = 20, 0, -1 do
            script.Parent.Position = script.Parent.Position - Vector3.new(0, 0.1, 0)
            wait(0.01)
        end
        end
    end
    end
end


Ad

Answer this question