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

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

Asked by 6 years ago

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.

0
Module scripts User#19524 175 — 6y
0
that doesn't tell me much lolkid007 43 — 6y
0
learn about them or stick with _G User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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

0
This would print nil. Avigant 2374 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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.

Answer this question