Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make my CFrame loop over and over?

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)

2 comments

0

What do you mean "this doesn't seem to loop"? What does it do instead?

0

Currently it freezes at position (-98, 6.7, -15)

1 answer

✓ Accepted answer

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()

This discussion is preserved as it was. New answers, comments, and votes are closed.