Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you require variables?

I'm trying to get the server to require a variable which obviously doesn't work. Can someone point me in the right direction on how to translate this thing in order for the server to recognize it? I've tried tonumber() and tostring() but it still wouldn't work. Thanks.

local variable = 2621001203
require(variable)

1 comment

0

The require function is for using a ModuleScript which is in your game. Are you trying to get a ModuleScript into your game by asset ID, or use a ModuleScript from another script, or something else?

1 answer

Lua:Require only works for module scripts, which loads in a ModuleScript for a predefined library(it would be the ModuleScript since this is Roblox Lua).

I am assuming that you want to require a ModuleScript, you can just

local ModuleScript = require(ASSETID OF MODULE)

If you want to use the module, you can use the variable and use it's contents

-- This module is in Workspace

local module = {}

local function module.Printer()
	print("test")
end

return module

You would access it by

local MDScript = require(game.Workspace.ModuleScript)

MDScript.Printer()

-- Alternatively

require(game.Workspace.ModuleScript).Printer()

This discussion is preserved as it was. New answers, comments, and votes are closed.