wait(2) spin() function spin() for initial = 1, 50 do local xAxis = game.Workspace.Fan local rotation = CFrame.Angles(math.rad(10),0,0) xAxis.Cframe = rotation end end
Code above, I'm not quite sure why it's not operating. I'm fairly new to LUA and would like to find out how to manually step through each line so I can debug future scripts myself. Loop body does not work by itself, not with loop, and not with function call. I just want to make a fan spin, hence I'm just changing the rotational CFrame by 10 degrees. Perhaps I need to call the script somehow?
EDIT: I've just began researching events. I don't necessarily want it to be "triggered" though, I just want it to be running consistently. Perhaps this is not my problem, the search continues.
Could be wrong but I think you have to do
local xAxis = game.Workspace.Fan local rotation = CFrame.Angles(math.rad(10),0,0) xAxis.Cframe = xAxis.CFrame * rotation -- multiply current cframe by rotation for it to rotate, not set it as the rotated CFrame
You would want to use Vector3.new
to make sure its formatted as a vector. It probably wouldn't spin because the orientation has no changing variable (i
in my example). And finally its better to just have the code in one line rather then setting a bunch of variables.
wait(2) while true do for i=1,50 do game.Workspace.Fan.Orientation = CFrame.fromEulerAnglesYXZ(Vector3.new(10*i,0,0)) end end
Technically you don't need to use fromEulerAnglesYXZ
but its a little more universal and makes it easier to understand.
This isn't the most clean way but it should work and is written similarly to your code.
I'll answer it myself. I thought LUA functioned where the conditions for loops counted in seconds. It does not function in seconds. The script would run too fast, and I just wouldn't see it at all. I upped my conditions to take in 500 and decrement to 0, it works. Also, added a little more just to help visually for my fan.
Also, thanks to Benbebop and plagueus for allowing me to try different and more efficient code.
while true do wait(20) for i = 0, 500, 1 do script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(math.rad(0.1*i), 0, 0) wait() end for i = 500, 0, -1 do script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(math.rad(0.1*i), 0, 0) wait() end end