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 a script keep a pattern?

I want to make an object fully rotate, so im doing a script like this

brick = Instance.new("Part", game.Workspace)
brick.Name = "Hello"
brick.Size = Vector3.new(4,4,6)
brick.Position = Vector3.new(1, 19, 1)
brick.Anchored = true
brick.Rotation = Vector3.new(0.2,0,0)
wait(0.1)
brick.Rotation = Vector3.new(0.4,0,0)
wait(0.1)
brick.Rotation = Vector3.new(0.6,0,0)
wait(0.1)
brick.Rotation = Vector3.new(0.8,0,0)
wait(0.1)
brick.Rotation = Vector3.new(1,0,0)
wait(0.1)
brick.Rotation = Vector3.new(1.2,0,0)
wait(0.1)
brick.Rotation = Vector3.new(1.4,0,0)
wait(0.1)
brick.Rotation = Vector3.new(1.6,0,0)
...

But, I want to make it like a pattern so I don't have to make it 1 by 1. I thought of something that would take the number in the line before and then add 0.2. so it goes like Vector3.new(0.2,0,0) and then is (0.2,0,0) and keeps adding to until it fully rotates.

1 comment

0

Just a suggestion in case Xetrax's help doesnt work then try using CFrame.new instead of Vector3.new

2 answers

✓ Accepted answer

Do you mean like a loop?

for Num = 1, 360/0.2 do
	brick.Rotation = brick.Rotation + Vector3.new(0.2, 0, 0)
	wait(0.1)
end	--[ This is a *For* loop, for loops can be used in many ways, as they stop once "Num" reaches the second number (which I have put as division (360/0.2), once Num reaches the limit specified, the loop will stop and your brick should have rotated one full 360 degree turn. ]

--With that in mind, if you want the brick to rotate infinitely, just do:

while true do
	brick.Rotation = brick.Rotation + Vector3.new(0.2, 0, 0)
	wait(0.1)
end	--[ This is a *While* loop, while loops are infinite, unless you put in the break command, which ends any loop, no matter if its a For or While; NEVER set a While loop with no wait() in it, this may cause your game to crash as it will devote all of its processing power to computing that loop as fast as possible with no break. ]

Hope that helps, if this doesn't work, hopefully someone else will answer your question the way you need. Regards, Xetrax

5 comments

0

Btw, the words enclosed in --[ ]-- are how I write my comments in scripts, they shouldn't bother the script at all if you copy and paste it and then try to run it.

0

Thanks man!

0

No problem! :D

0

An extended comment requires two open brackets and two close brackets, not one.

0

Not what I'm going for, its just my style.

I think you are trying to say you want to do it without writing so many lines I guess.

Try doing a while loop, then inside the loop, add the rotation by how much you want.

Don't forget to use wait, or your part won't work!

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