AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 13 Dec 2015 10:20 PM |
game:GetService("RunService").RenderStepped:connect(function() if Status == false then return -- Doesn't work like a break end end)
Is there a way to end the function? Usually I'd do a while wait() do loop, and then I can end it with a break. But with renderstepped (trying to get even smoother movements), trying to do return doesn't work and end the function completely. How can I get the same functionality, while keeping renderstepped? |
|
|
| Report Abuse |
|
|
hkep
|
  |
| Joined: 19 Jul 2014 |
| Total Posts: 550 |
|
|
| 13 Dec 2015 10:25 PM |
local RS = game:GetService("RunService"); Con = RS.RenderStepped:connect(function() if Status == false then Con:disconnect(); end; end);
-- Honestly I would not do it like that, I would do this to prevent overlapping -- assuming that the if statement is placed at the end ^
local RS = game:GetService("RunService"); while Status do RS.RenderStepped:wait(); -- code end; |
|
|
| Report Abuse |
|
|
hkep
|
  |
| Joined: 19 Jul 2014 |
| Total Posts: 550 |
|
|
| 13 Dec 2015 10:27 PM |
One more thing, RenderStepped is an event. You have to disconnect it if it was connected. the wait method waits until the event is called, it returns the argument giving too. So:
local Char = Player.CharacterAdded:wait(); -- will wait until character is added, then returns the Character. |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2015 10:29 PM |
local Connection = game:GetService("RunService").RenderStepped:connect(function() -- code here end)
Connection:disconnect() -- ends the connection |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2015 10:38 PM |
Use BindToRenderStep:
http://wiki.roblox.com/index.php?title=API:Class/RunService/BindToRenderStep |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2015 10:43 PM |
Forgot to provide an example:
local RunService = game:GetService("RunService");
local Object = {MyVariable = 1};
Object.Increment = function() Object.MyVariable = Object.MyVariable + 1; print("MyVariable | " .. Object.MyVariable); if (Object.MyVariable == 60) then RunService:UnbindFromRenderStep("Increment"); end end
RunService:BindToRenderStep("Increment", Enum.RenderPriority.First.Value, Object.Increment); |
|
|
| Report Abuse |
|
|