robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 07 May 2014 07:52 PM |
Humanoid = script.Parent.Parent.Humanoid running = false Humanoid.Running:connect(function(speed) if speed > 0 then running = true else running = false end end)
while running do wait() print'RUN RUN URNR' end
while it's running, it's supposed to spam the output, but, it doesn't. probably a simple answer, i actually can kinda see what's wrong, but i'm not sure WHY it's wrong. -=Robo=- |
|
|
| Report Abuse |
|
|
|
| 07 May 2014 07:54 PM |
The running variable is initially set to false. So the while loop won't run. You may want this instead:
while true do wait() if running then print'RUN RUN URNR' end end |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 07 May 2014 07:57 PM |
wouldn't while wait() do be more efficient? also, running a while loop to check if it's running would be inefficient, wouldn't it? -=Robo=- |
|
|
| Report Abuse |
|
|
|
| 07 May 2014 08:00 PM |
In all honesty, I don't think it matters if you use while wait() do or while true do wait(). It's all preference.
Using a while loop isn't the most efficient way to do this, but it works. Another way would be using value objects and the Changed event. |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 07 May 2014 08:41 PM |
I had thought of that, but, I prefer keeping it all in a script. I wish there was some way to make a changed event for variables in scripts, that'd be sweet, though I assume it'd contradict some other script things though -=Robo=- |
|
|
| Report Abuse |
|
|
|
| 07 May 2014 10:16 PM |
| You can, with metatables. It's a tad more complicated, though, but easily possible. Heck, you could even add a .Changed event to the environment itself. |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 07 May 2014 10:32 PM |
There's a metamethod similar to the changed event? :o -=Robo=- |
|
|
| Report Abuse |
|
|
|
| 07 May 2014 11:01 PM |
Well, not exactly. You'll have to use __index and __newindex. |
|
|
| Report Abuse |
|
|