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

How do I share variables between scripts, possibly using _G?

Im starting to learn how to use _G and I've tried to use it as a variable sharer between scripts, but it doesn't seem that there is a possible way to do so. If there is another method I could use, please tell me, I'm always looking for better ways to improve my scripting capabilities.

3 comments

0

Module scripts

0

that doesn't tell me much

0

learn about them or stick with _G

2 answers

Module script~

local module = {}

function module.variable()
    ["Variable"] = "something"
end

return module 

From the server/client

local moduleScript = require(game:GetService("ServerScriptService").ModuleScript)

print(moduleScript.Variable) 

i might be wrong

1 comment

0

This would print nil.

Have you tried using the value instances (BoolValue, IntValue, NumberValue, StringValue, Vector3Value, etc.)? Just set the value objects value then read it from another script.

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