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
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
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.
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!
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 ^
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
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
Try adding a wait()
Errors?
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.