Why isn't my sprint system working

I am trying to make a sprinting system. I keep getting an error that i have made an infinite loop. I am new to loops and how they work, so I can’t see the issue. After watching a few tutorials, I have made a completely different one to the ones that they made. You might say that I should follow the tutorials, but I want to push myself and learn a new feature, and also to potentially make a more efficient method of sprinting.

I made my sprint a function that checks if the player is running and then should take away stamina from the player. If the players health is equal to 0, it should then set the Can Run Boolean to False.
239135-
][2]

This is where I am firing off the event.

Does the IsRunning variable ever become false? Because if not, that while loop will never stop and will therefore cause an infinite loop :wink:

You can’t use “latent nodes” (anything with a clock icon on it) within any loop body, it doesn’t work. It will just continuously execute into the delay thinking it has “completed” execution. The loop does not wait for the completion of your entire script before firing off again. It is only doing this:

  1. check “is running”
  2. TRUE? fire execution (which is your delay) so it waits 0.2 seconds before continuing that execution path however, the “loop” thinks it has finished “one” loop, so it once again asks itself the question
  3. “is running”?
  4. TRUE? fire execution (which is another delay)

This process repeats on tick, so that 0.2 sec delay basically causes a bottleneck of “execution” and when it finally reaches 0.2 seconds it will only execute once, OR in your case the processor quits and says there is an infinite loop.

If you want to actually place a delay node into a loop macro I have made a tutorial for this. It is modifying a “for each loop” but it will work just the same for modifying a “for loop”. I have posted the link below.