#Using a function from a module script to update a local variable of another script
1 messages · Page 1 of 1 (latest)
Where code
are you asking how or do you have an issue with your code
Im asking how
try using getfenv(). It gets the function's environment (variables)
Well you'd need to communicate between scripts, like with a BindableEvent if both are server scripts
1 is server and the other is module script, i did require the module in the server so they do have connection, but idk how to change a local var without using return
i cant find a proper page explaining this func, can you explain for me?
Oh, well you have to return a table with the variable in it.
So like
local module = {}
module.MyValue = 0
return module
then
local module = require(module)
module.MyValue = 5
The variable i need to change is in the server script
Well then you need to rethink how you're storing that local value
Like what is the value and why are you trying to change it
So it’s not possible?
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
it gets all the variables. Example
m = 5
print(m)
equals
getfenv().m = 5
print(getfenv().m)
@stray cargo
im readin
I just changed so you can understand better
as the title said, it has to use the module script's function, this func is set in the server script
by making this function in the script you can change the variable by using it in the module
** You are now Level 4! **