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

Cant set CFrame on shoulder more than once?

Asked by 5 years ago

I'm trying to make a walking animation with CFrame, without the animation plugin, and since I'm new to this I don't know why I can't set the CFrame of the shoulder more than once.

Run.RenderStepped:connect(function()
        leftArm.C1 = CFrame.new(0,0.5,-0.5) * CFrame.Angles(0,0,-math.pi/4)
        wait(2)
        leftArm.C1 = CFrame.new(0,0.5,-0.5) * CFrame.Angles(0,0,math.pi/4)
    end)
0
The wait(2) on line 3 won't "pause" RenderStepped. The RenderStepped event will continue firing. Optikk 499 — 5y
0
you could make it recursively run through the animation and end when it is complete, I'll type it up for you right now SteamG00B 1633 — 5y

1 answer

Log in to vote
1
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

So I assume you want the frames to change every 2 seconds judging by your wait(2) line.

function animate(step, last)
    if step == 0 then
        leftArm.C1 = CFrame.new(0,0.5,-0.5) * CFrame.Angles(0,0,-math.pi/4)
        wait(2)
        if step ~= last then
            animate(step+1)
        end
    elseif step == 1 then
        leftArm.C1 = CFrame.new(0,0.5,-0.5) * CFrame.Angles(0,0,math.pi/4)
        wait(2)
        if step ~= last then
            animate(step+1)
        end
    end
end

animate(0,1)--starts off at 0 and runs until it reaches 1

The benefit of this over RenderStepped is that it allows you to add wait() commands, and also if you want to add another frame, you'd just add another elseif block with step == 2 (in this case) and then change the CFrame. The only downside I can see to this method is that if you want to add another frame in between 2 frames, you'll have to increase all of the step numbers in the blocks after the one you added by 1. But even if this was a for loop, you'd still have to do that anyway, and I just wrote it this way because I personally prefer recursive functions over standard loops.

This solution is what you are asking for, but in all honesty, learning the animation plugin is probably going to make this process a whole lot easier than you realize.

0
Thanks, and yeah I already know how to use the animation plugin but just wanted to try this. docrobloxman52 407 — 5y
Ad

Answer this question