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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Returning variable from ModuleScript

Previous Thread :: Next Thread 
ByThefault is not online. ByThefault
Joined: 26 Aug 2015
Total Posts: 227
15 Sep 2015 11:08 AM
How would I do this?

--ModuleScript
func = function()
return false
wait(10)
return true
end

--Script
local mod = require(ModuleScript)
mod()
repeat wait(1) until mod == true

Would that work?
Report Abuse
Scripterity is not online. Scripterity
Joined: 30 Mar 2014
Total Posts: 677
15 Sep 2015 11:09 AM
Test it to see if it works, and by the looks of it, it should work.
Report Abuse
ThatChristianGuy is not online. ThatChristianGuy
Joined: 14 Jun 2014
Total Posts: 1283
15 Sep 2015 11:10 AM
--ModuleScript
func = function()
return false
wait(10)
return true
end
return func -- very important

--Script
local mod = require(ModuleScript)
mod()
repeat wait(1) until mod == true


--ThatChristianGuy
Report Abuse
ThatChristianGuy is not online. ThatChristianGuy
Joined: 14 Jun 2014
Total Posts: 1283
15 Sep 2015 11:10 AM
Also keep in mind that you can only have one return in a block, so the two returns in your function will error.


--ThatChristianGuy
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
15 Sep 2015 11:11 AM
Please guys. This will not work at all.
You can't return two things. This won't work on a level that I won't even bother correcting any of you Dx
Report Abuse
ThatChristianGuy is not online. ThatChristianGuy
Joined: 14 Jun 2014
Total Posts: 1283
15 Sep 2015 11:12 AM
I mentioned that already Jarod.


--ThatChristianGuy
Report Abuse
Scripterity is not online. Scripterity
Joined: 30 Mar 2014
Total Posts: 677
15 Sep 2015 11:12 AM
I meant it'll run, what he's trying to do won't work.
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
15 Sep 2015 11:12 AM
You need to explicitly return something at the end of the ModuleScript. Act as if the entire script itself is an enclosed function.

ModuleScript:
return "Hi!"

Script:
print(require(ModuleScript)) --> Hi!
Report Abuse
ThatChristianGuy is not online. ThatChristianGuy
Joined: 14 Jun 2014
Total Posts: 1283
15 Sep 2015 11:13 AM
Scripterity, his script tries to call a nil value (mod).


--ThatChristianGuy
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
15 Sep 2015 11:14 AM
ThatChristianGuy, you didn't finish posting before I started.



"Scripterity, his script tries to call a nil value (mod)."
But his script will still run, so Scripterity was correct.
Report Abuse
ThatChristianGuy is not online. ThatChristianGuy
Joined: 14 Jun 2014
Total Posts: 1283
15 Sep 2015 11:15 AM
Any script will run as long as it's not disabled.


--ThatChristianGuy
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
15 Sep 2015 11:16 AM
Not really.


Try running this script:
(]+++=//*^%ne\52gt}
That will be a syntax error, not a runtime error.
Report Abuse
ByThefault is not online. ByThefault
Joined: 26 Aug 2015
Total Posts: 227
15 Sep 2015 11:34 AM
func = function()
return false
wait(10)
return true
end
return func

--Script
local mod = require(ModuleScript)
mod()
repeat wait(1) until mod == true

How can I make this work?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
15 Sep 2015 11:43 AM
func = function()
wait(10)
return true
end
return func

--Script
local mod = require(ModuleScript)
mod() -- This waits ten seconds

How can I make this work?
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