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

How to make my CFrame loop over and over?

Asked by 10 years ago

This is probably simple, but I just learned about CFrame. I'm trying to make the part this script is in, Move up and down over and over in the current position it is already in. This does not seem to loop.



function movement() while true do wait() for y = -5,5, 0.1 do script.Parent.CFrame = CFrame.new(-98, 1.7, -15) * CFrame.new(0, y, 0) end end end movement()

Is there another way to move my part from a position instead of assigning it to stay in the X axis and Y axis above? i.e. if I dragged this part somewhere else, It stays there not moves(Minus Up and Down)

0
What do you mean "this doesn't seem to loop"? What does it do instead? BlueTaslem 18071 — 10y
0
Currently it freezes at position (-98, 6.7, -15) alphawolvess 1784 — 10y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

The problem is you didn't put a yeild in your for loop - It would just immediately get stuck somewhere. Try this

function movement()
    local down = false
    while wait() do
        down = not down
        for y = 1,10 do
            wait(.05)
            if down then
                num = -.1
            else
                num = .1
            end
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,num,0)
        end
    end
end

movement()
Ad

Answer this question