The code inside the if statements in both of your loops will only run a single time.
In the first loop, this is because moving must equal false in order for the code to be executed.
This is fine for the first iteration, but then you change the value of moving -- you make it equal true.
This means that once the code reaches the second iteration, moving now equals true and will not pass the if statement.
It's the same for the second loop, only reverse.
Because of the way your code is executed -- left to right, top to bottom -- the second loop won't start until the first one is finished. Therefore, the problem talked about in your post is no problem at all.
You likely added your debounce variable so that people won't be able to glitch out the animation. Just use it like a normal debounce, checking it before you start anything else.
local moving = false
script.Parent.Activated:connect(function()
if not moving then
moving = true
RightShoulder = script.Parent.Parent.Torso["Right Shoulder"]
for i = 1,10 do
RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0,0,.1)
wait()
end
for i = 1,10 do
RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0,0,-.1)
wait()
end
moving = false
end
end)
Although you really should look into animations, as they will allow smoother and more complex movements.
2 comments
I tried animations, but when I tested it, the script wouldn't work with the tool equipped. So I tried this. Thanks!
That's probably because something in the tool is welded in some way that prevented the motion.