|
| 07 Jun 2012 03:02 PM |
I am figuring out how CFrame works using scripts. I made this script to make a brick move backward, and then forward again to the original position. I posted once, fixed my mistake, but now I have run into another problem. It's not an error, but when the brick reaches the X of 59, it stops instead of reversing direction. This means that both 'if' statements are running at the same time. How do I fix this?
Code:
local thepart = script.Parent.ThePart local theAngle = 49 active = false
wait(2)
while true do if theAngle < 59 then active = true theAngle = theAngle + .01 thepart.CFrame = CFrame.new(theAngle, 5, 0) * CFrame.Angles(0, 0, 0) print ("The X of #2 is: " ..theAngle) print ("#2 is going forward.") end if theAngle > 59 then theAngle = theAngle - .01 thepart.CFrame = CFrame.new(theAngle, 5, 0) * CFrame.Angles(0, 0, 0) print ("The X of #2 is: " ..theAngle) print ("#2 is going backward.") end wait(.01) end |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2012 03:05 PM |
57, 58 < 59 < 60, 61
You can't use 59 in this case, try using >= or <= in either of the cases, or use else:
while true do if theAngle < 59 then active = true theAngle = theAngle + .01 thepart.CFrame = CFrame.new(theAngle, 5, 0) * CFrame.Angles(0, 0, 0) print ("The X of #2 is: " ..theAngle) print ("#2 is going forward.") else --if theAngle => 59 then theAngle = theAngle - .01 thepart.CFrame = CFrame.new(theAngle, 5, 0) * CFrame.Angles(0, 0, 0) print ("The X of #2 is: " ..theAngle) print ("#2 is going backward.") end wait(.01) end |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2012 03:13 PM |
I tried your script, I had an issue I was having earlier. The problem with your script is that it begins to move it back, but when the loop goes through again, it sees that the brick is now less than 59 and it moves forward. It continues to do this forever.
Any other suggestions? |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2012 03:14 PM |
Wait, I think I found the solution to the original code.
I forgot to implement the active value into the second if statement. |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2012 03:15 PM |
| Because thats how you have it set to work. ._. You want it to move up to 59 then back to 0, then up and down over and over again? |
|
|
| Report Abuse |
|
|