joji1000
|
  |
| Joined: 23 Aug 2013 |
| Total Posts: 291 |
|
|
| 23 Apr 2017 11:25 AM |
It's came to my attention that many people use a 'while true do' when they want an infinite loop, DON'T. While true do strains the server severely, mostly when used in multiple instances (Not to mention the risk of forgetting the 'wait()').
An alternative is to use the following command:
For the client do: game:GetService('RunService').RenderStepped:connect(function(Delta) --[[This is a far more efficient loop, while true do in multiple instances are separate, Renderstepped will fire every frame and is a function so it is 1 instance. Delta describes how long it takes for a frame to be fired (normally per a milisecond aka 1/60th of a second).]] end)
For the server do: game:GetService('RunService').Stepped:connect(function(Delta) --[[Similar to RenderStepped but works off of the servers rate of is 1/30 of a second instead of a milisecond.]] end)
Use your loops wisely, while true do is straining to the server/client, use .Stepped or .RenderStepped instead. |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2017 11:27 AM |
while true do wait( n )
end
is good for when you want to run something every n seconds such as autosave or http requests dont make it look obsolete :( |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2017 11:27 AM |
| you also forgot Heartbeat which should be used instead as it does not yield the frame and you forgot to talk about BindToRenderStep which is better than connect so not very helpful |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 23 Apr 2017 11:32 AM |
This thread is pure stupidity.
The things you described are still loops. And they won't "strain the server" any less.
Code is running regardless of whether it is in an event loop or a loop construct.
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
| |
|
|
| 23 Apr 2017 11:34 AM |
also now that i noticed it, did he just say that u shouldnt use while true do end
hahahahaha nobody does, not unless they are coding for the very first time |
|
|
| Report Abuse |
|
|
OVOClxaz
|
  |
| Joined: 03 Sep 2012 |
| Total Posts: 2 |
|
|
| 23 Apr 2017 11:45 AM |
| The wait is something you can't forget in while true do, even I fu don't want it just don't fill the "()" with a number |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2017 11:48 AM |
| RenderStepped can be worse since it fires more than loops do most of the time. |
|
|
| Report Abuse |
|
|
joji1000
|
  |
| Joined: 23 Aug 2013 |
| Total Posts: 291 |
|
|
| 23 Apr 2017 12:00 PM |
| RenderStepped and Stepped are prepresent in game memory and are already in constant fire, wasting it would be stupid. while true do loops in multiple instances can in fact strain the server (geuss I didn't describe that it will in large amounts.) and when I say to not use while true do loops I meant that if you will use them, only use them if there is a constant timer needed, and don't use them often. They are both loops but thats where the similarities end, RenderStepped is a function, while true do is an instance. |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2017 12:02 PM |
1) bind to render stepped* 2) render stepped yields the frame and should be used for NOTHING other than things that need to occur every frame like camera movement |
|
|
| Report Abuse |
|
|
| |
|
| |
|
joji1000
|
  |
| Joined: 23 Aug 2013 |
| Total Posts: 291 |
|
|
| 23 Apr 2017 12:08 PM |
| The difference between a RenderStepped and a instance? say if you used .Touched in 2 different script but on the same part, they will fire at the same time when said part is touched, now RenderStepped works similar to that in the fact for the specified client any instance of RenderStepped fires at the same time, the are more efficient due to the simple fact that it runs off of 1 core RenderStepped in said client. so thousands of Renderstepped instances would technically be one. If RenderStepped strained the client or server, then no game would be playable, each frame of your screen is a render, the function just fires when ever the frame is rendered. |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2017 12:12 PM |
um kid, like i told you before, heartbeat
if you want proof
game:GetService('RunService').RenderStepped:connect(function() wait(1) end) |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2017 12:13 PM |
hold on wait actually wont yield it, just run a massive for loop
a dev forum thread specifies this |
|
|
| Report Abuse |
|
|
joji1000
|
  |
| Joined: 23 Aug 2013 |
| Total Posts: 291 |
|
|
| 23 Apr 2017 12:18 PM |
Sorry man, but all it does it just run a wait in the RenderStepped, and plays the action, aka it will fire at the same rate at constant no problem its just that the effect inside of it will take longer to begin
if you wait 1 second then all it will do is just wait 1 and then fire at a fast pace like before, as i stated, it is a function, not an instance. |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2017 12:26 PM |
a dev forum thread specifies this [2] u r highly misinformed
devforum.roblox.com/t/runservice-heartbeat-switching-to-variable-frequency/23509/7 |
|
|
| Report Abuse |
|
|
joji1000
|
  |
| Joined: 23 Aug 2013 |
| Total Posts: 291 |
|
|
| 23 Apr 2017 01:02 PM |
| Just learn't about heartbeat, apparently it is more efficient then RenderStepped and stepped, good to know. |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
| |
|