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

Why does the part wont rotate constantly as in script?

Asked by 7 years ago

So, hi! I have problem with this normal script. I dont know why does it wont rotate part constantly.... I dont know how to use "for" loops... So please help me!

p = script.Parent.Parent.VIPAD

while true do
    p.Orientation.Y = 40.52
    wait(0.1)
    p.Orientation.Y = 45.52
    wait(0.1)
    p.Orientation.Y = 50.52
    wait(0.1)
    p.Orientation.Y = 55.52
    wait(0.1)
    p.Orientation.Y = 60.52
    wait(0.1)
    p.Orientation.Y = 65.52
    wait(0.1)
    p.Orientation.Y = 70.52
    wait(0.1)
    p.Orientation.Y = 75.52
    wait(0.1)
    p.Orientation.Y = 80.52
    wait(0.1)
    p.Orientation.Y = 85.52
    wait(0.1)
    p.Orientation.Y = 90.52
    wait(0.1)
    p.Orientation.Y = 95.52
    wait(0.1)
    p.Orientation.Y = 100.52
    wait(0.1)
    p.Orientation.Y = 105.52
    wait(0.1)
    p.Orientation.Y = 110.52
    wait(0.1)
    p.Orientation.Y = 115.52
    wait(0.1)
    p.Orientation.Y = 120.52
    wait(0.1)
    p.Orientation.Y = 125.52
    wait(0.1)
    p.Orientation.Y = 130.52
    wait(0.1)
    p.Orientation.Y = 135.52
    wait(0.1)
    p.Orientation.Y = 140.52
    wait(0.1)
    p.Orientation.Y = 145.52
    wait(0.1)
    p.Orientation.Y = 150.52
    wait(0.1)
    p.Orientation.Y = 155.52
    wait(0.1)
    p.Orientation.Y = 160.52
    wait(0.1)
    p.Orientation.Y = 165.52
    wait(0.1)
    p.Orientation.Y = 170.52
    wait(0.1)
    p.Orientation.Y = 175.52
    wait(0.1)
    p.Orientation.Y = 180.52
    wait(0.1)
    p.Orientation.Y = 185.52
    wait(0.1)
    p.Orientation.Y = 190.52
    wait(0.1)
    p.Orientation.Y = 195.52
    wait(0.1)
    p.Orientation.Y = 125.52
    wait(0.1)
    p.Orientation.Y = 130.52
    wait(0.1)
    p.Orientation.Y = 135.52
    wait(0.1)
    p.Orientation.Y = 140.52
    wait(0.1)
    p.Orientation.Y = 145.52
end
0
With functions like this just use while wait(0.1) do end YouSNICKER 131 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

You can't assign a number to only one component to the Orientation (X,Y,Z) of a part. It won't work. Instead, you have to use Vector3. So in this case it would go like this:

p.Orientation=Vector3.new(0,40.52,0)

And then you would repeat this as much as you need to. However because this code is hideous and very hard to edit, I'm going to write you up a for loop.

for i=1, 60 --[[ you can change this to any number you want. This shows the loop how many times you want it to repeat ]] do Wait(0.1) --[[ How much time the script will wait till the loop repeats again ]]
    p.Orientation=p.Orientation+Vector3.new(0,0.5,0) --[[ you can edit these numbers as well to how much you need the part to rotate each time the for loop repeats]]
end

This is a simple for loop that you can easily edit. Remember though, you must always add a wait! otherwise the whole code will be completed in the blink of an eye. This is especially necessary with While loops because they repeat forever and will freeze your game.

Ad
Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
7 years ago
Edited 7 years ago

for loops make your code more efficient. The 77 lines of code right there could be shortened to 4

for i = 40.52,145.52,5 do
    p.Orientation = Vector3.new(p.Orientation.X,i,p.Orientation.Z)
    wait(0.1)
end

If you read your output, it will probably say "Y cannot be assigned to". This is becuse the axes are read only. To set the orientation, you must set the whole thing. Read about Vector3 here:

http://wiki.roblox.com/index.php?title=API:Vector3

And for info about for loops:

http://wiki.roblox.com/index.php?title=Loops#For

Answer this question