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

CFrame.Angles script not functioning. How do I make my fan spin?

Asked by 4 years ago
Edited 4 years ago
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.

0
If you want it to go constantly just use a "while true do" loop. Benbebop 1049 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
This would cause the fan to accelerate exponentially because you are multiplying and vectors do not work like that. Benbebop 1049 — 4y
0
It doesn't seem to work, multiplying by rotation. But I found that my "for" loops aren't working, "while true do" works but I want to come out of the loop at some point. Ethan_Tano 2 — 4y
Ad
Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
this overcomplicates things in my opinion, their solution was fine they just didnt do the CFrame operations correctly plagueus 44 — 4y
0
I found that my "for" loops aren't working whatsoever. I tried just a while true and the fan can run consistently, however I want to break out the loop so I can slow down the fan or something else. Ethan_Tano 2 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Answer this question