Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is require() and how would I use it?

Asked by 9 years ago

I see quire in a few scripts(And I mean very few). What does the require() do? Does it load a link or asset kind like the http getasync()? And how would I use require?

Is it kind like : http://www.roblox.com/Idk-item?id=184517286?

require(184517286)

--Comment Posted By Gravity Studios.

1 answer

Log in to vote
5
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

require loads a ModuleScript so that you can use the function / object that the script exports.

Here is a ROBLOX blog posts with more articles


Normally, you would pass the ModuleScript to require, e.g.

helperFunctions = require( workspace.MyModule )

helperFunctions.add( ... blah blah )

I cannot find documentation about the require that takes a number. I imagine that it runs the ModuleScript uploaded to the particular asset, if the place has permission to insert that script (or maybe in general, since this can be done more or less securely, I'm not sure)


For visibility, Adarkthescoundrel's Comment Below

You can require the assetID of a ModuleScript uploaded directly with the name 'MainModule', as long as you have access to that Model (i.e. it's free or you own it.).

A tidbit I found is that any children of the ModuleScript are also included, so you can require the ModuleScript and have access to any kind of ROBLOX Object without having to use the InsertService.

2
Thank you taslem! MessorAdmin 598 — 9y
3
You can require the assetID of a ModuleScript uploaded directly with the name 'MainModule', as long as you have access to that Model (i.e. it's free or you own it.). A tidbit I found is that any children of the ModuleScript are also included, so you can require the ModuleScript and have access to any kind of ROBLOX Object without having to use the InsertService. adark 5487 — 9y
Ad

Answer this question