Hello,
The value of Degrees and DeltaRotation are constantly changing as this whole loop is in a renderstepped function.
1 | for i = Character.Humanoid.WalkSpeed, 22 , 0.5 do |
2 | if Degrees > 45 or DeltaRotation.magnitude > = 8 then |
3 | print ( "broken" ) |
4 | break |
5 | else |
6 | Character.Humanoid.WalkSpeed = i |
7 | end |
8 | end |
However, when the Degrees and DeltaRotation meet the requirements of the if statement, the output does not print "broken". Instead the WalkSpeed increases.
I appreciate anyone willing to take the time to point me in the right direction in to why this loop may not be breaking.
You should try using repeat.... until... like:
1 | repeat Character.Humanoid.WalkSpeed = 22 wait() |
2 | until Degrees > 45 or DeltaRotation.magnitude > = 8 |
Edit: I forgot about the wait(), its required to prevent a timeout!
Thank you, I've just looked in to repeat and until and also while and do loops.
I've fiddled around with the code and took in to account what you said and ended up with the below:
1 | while Degrees < = 45 and DeltaRotation.magnitude < 8 do |
2 | wait() |
3 | repeat |
4 | WalkSpeed = WalkSpeed + 0.5 |
5 | wait() |
6 | print (Character.Humanoid.WalkSpeed) |
7 | until Degrees > 45 or DeltaRotation.magnitude > = 8 |
8 | end |
The code shows no errors however my walkspeed doesn't appear to be changing.
EDIT:
Here is a larger section of the code. I've reverted to the following code which sort of works:
01 | -- 1st if statement |
02 | if Degrees < = 45 and DeltaRotation.magnitude < 10 then |
03 | for i = Character.Humanoid.WalkSpeed, 22 , 0.5 do -- LOOP |
04 | Character.Humanoid.WalkSpeed = i |
05 | if Degrees > 45 or DeltaRotation.magnitude > = 10 then |
06 | break |
07 | end |
08 | wait( 0.2 ) |
09 | end |
10 |
11 | -- 2nd if statement |
12 | elseif Degrees > = 101 and Degrees < = 180 and DeltaRotation.magnitude < = 220 then |
13 | Character.Humanoid.WalkSpeed = 12 |
14 | end |
The problem I'm having is that when the 2nd if statement is triggered, the loop in the 1st if statement continues to finish but I want it to break as soon as the 2nd if statement is triggered.