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 » Scripters
Home Search
 

Re: Ending renderstepped function?

Previous Thread :: Next Thread 
AntiFiter is not online. 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 is not online. 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 is not online. 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
CLIMAXIMUS is not online. CLIMAXIMUS
Joined: 22 Jun 2012
Total Posts: 1738
13 Dec 2015 10:29 PM
local Connection = game:GetService("RunService").RenderStepped:connect(function()
-- code here
end)

Connection:disconnect() -- ends the connection
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
13 Dec 2015 10:38 PM
Use BindToRenderStep:

http://wiki.roblox.com/index.php?title=API:Class/RunService/BindToRenderStep
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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