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: While loop question.

Previous Thread :: Next Thread 
robocu3 is not online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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 is not online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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 is not online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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 is not online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
07 May 2014 11:01 PM
Well, not exactly.
You'll have to use __index and __newindex.
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