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

How do you require variables?

Asked by 5 years ago

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)
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? aschepler 135 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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()
Ad

Answer this question