generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Please Read 2

Previous Thread :: Next Thread 
fireheart568 is not online. fireheart568
Joined: 04 Jan 2009
Total Posts: 1285
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
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
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
fireheart568 is not online. fireheart568
Joined: 04 Jan 2009
Total Posts: 1285
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
fireheart568 is not online. fireheart568
Joined: 04 Jan 2009
Total Posts: 1285
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
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image