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

Omg why won't all my titles work please just read this? D:

Asked by 7 years ago

Hi, I was a Lua dev. before but I have not used it in 3 months.. Now I need to make an orientation script This is my script wich fails:

local x = 0
while true do
    x=x+5
    if x = 360
        x = 0
    end
end
script.Parent.Orientation = x,0,0
0
script.Parent.Orientation = Vector3.new(x,0,0) put that inside of the loop and put some sort of yield in the loop or suffer LaeMVP 0 — 7y
0
Try adding a wait() Mineloxer 187 — 7y
0
Errors? Viking359 161 — 7y
0
To be honest if your trying to make a rotation remember to put the script under the object, make sure it is an object that you can rotate yourself. now if you want it to go in circles again and again, the while true do is needed. If you dont, just make a function like, function onClick() or just look up a command to "always do" like if 1 = 1 then script.Parent.Orientation = x,0,0 else wait(1) end. MarkHasReset 77 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago

First of all, the code which changes the Orientation of the object is not in the while loop, so it will never be run.

You need a then after an if statement's evaluation, and to check if two things are equal you need two equal signs. Simply using one means you are setting the variable to something else.

if x == 360 then --Two equal signs, and put a then after the evaluation
    x = 0
end

Also, there is no wait() in the while loop, so put simply, it will try to run itself millions and millions of times within a second, making it crash. You need to add it somewhere in there.

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Actually, there will be a continuous cycle of X being added by 1 every million times per second. This means that your Studios program will crash and Line 8 will NEVER be executed. I would advise you to use CFrame if you are trying to rotate a part/UnionOperation.

Example of rotating with CFrame;

local x = 0

while true do
    x = x + 0.1 --I would advise you to keep it below 1, not not a negative number
    script.Parent.CFrame = script.Parent.CFrame*CFrame.Angles(math.rad(x),0,0) --math.rad() just means that whatever is in the () will be rotated by that degrees on the x,y, or z 
    coordination.
    if x == 360 then
        x = 0
        --or this to stop the endless loop
        break
    end
    wait(1/25) --IMPORTANT TO HAVE WAIT! You can change 1/25 to whatever seconds to wait.
end

Hope this helped!

Log in to vote
0
Answered by 7 years ago

your if statement is wrong, it is suppose to be a double = and not 1 equal sign Oh and apparently in your case you Cannot put code after the loop

Example:

local x = 0
while wait() do
    x = x + 5
    if x == 360 then
        print("X = 360 degrees")
        script.Parent.Orientation = Vector3.new(x,0,0)
    end
end

This is as simple as it gets ^

Answer this question