#Using a function from a module script to update a local variable of another script

1 messages · Page 1 of 1 (latest)

stray cargo
#

title

#

not using return btw

wild comet
#

Where code

drifting lodge
muted shard
#

try using getfenv(). It gets the function's environment (variables)

drifting lodge
stray cargo
stray cargo
drifting lodge
stray cargo
drifting lodge
muted shard
#

in server:

requiredModule.ChangeVar = function (value:any)
  myVar = value
end

in module function:

thisModuleYouAreUsing.ChangeVar(123)
#

you need to declare the function before you launch the module function

muted shard
stray cargo
#

im readin

muted shard
#

I just changed so you can understand better

stray cargo
muted shard
main tuskBOT
#

studio** You are now Level 4! **studio

muted shard
#

okay here's an example

#

Server:

local module = require(myModule)
local myVar = 7

module.ChangeVar = function (value:any)
  myVar = value
end

module.Test()

print(myVar)

Module:

local module = {}

function module.Test()
  module.ChangeVar(90)
end

return module