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

How Would You Make Rotating Brick Positions?

I know how to make complete rotations for a brick, but how do you make rotations that stop at a certain point and not make the brick rotate fully?

Fully rotating script:

while true do
	script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)
	wait(0.02)
end

A recording of what I want to happen:

https://gyazo.com/0fde00cd2028caf9403d45eebd7a4a21

What's happening is that I want the brick to rotate at one position, stop, then rotate back. How would I do that?

1 answer

✓ Accepted answer

Hello,

One problem I noticed in your code is the fact that you are using a "while" loop. The way you are using a while loop makes an endless loop, as you most likely already know. I would recommend using a "for" loop. If you aren't familiar with "for" loops, here's an example:

for i = 1, 10 do --Sets a value and each time it loops it increaseas the value of "i" until it becomes 10, and then stops the loop. Basically makes whatever is between this line and the "end" happen 10 times.
	print("Hi")
	wait()
end

So, using a "for" loop, your code would look something like this:

for i = 1, 90 do
	script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0, 1, 0) --Notice I used "CFrame.Angles()", which is a newer version of CFrame.fromEulerAnglesXYZ(). CFrame.fromEulerAnglesXYZ() is depreciated, meaning no longer mainly used, and is usually looked down upon.
	wait()
end
for i = 1, 90 do --Starting another loop to go back
	script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0, -1, 0) --Backwards(negative) rotation.
	wait()
end

If you need any more help or clarification, feel free to comment.

1 comment

0

Oh thanks, I get an understanding of for loops and rotation now.

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