Set a Variable's value from a script to a value from a modulescript

i wanna set a Variable’s value from a script to a value from a modulescript
the script is serverside

Modulescript:
image
image

Script:
image
image

But it returns “nill” or “null” and never a “0” or a number
what am i doing here that’s wrong?

if you odnt mind me asking, what is “self”?

1 Like

image
a table containing some stats
this is from the module script

1 Like
local module = require(moduleScript)
module.Diamond = 10 --set value

print(require(moduleScript).Diamond) -- `10`
2 Likes

im still unsure by what “self” is. but if i understand your problem right you wanna have a function that you can call form a modulescript that will set “Diamonds” to 0?

1 Like

I want to set the serversided variable diamonds to the same amount of self.diamonds on the module script

i just don’t know how to get the value on modulescript to be put on a variable from a serverside script

1 Like

Wait so self.diamonds is a changing value or is it constant?

1 Like

Since plrClass.Diamonds is part of the module you can just run

local plrClass = require(PATH_TO_MODULE)
plrClass.Diamonds = newValue
print(plrClass.Diamonds)

However if you want it to be a local variable, you can use getters and setters similar to Java

local plrclass = {}

local Diamonds = 100

function plrclass:SetDiamonds(value)
	Diamonds = value
end

function plrclass:GetDiamonds()
	return Diamonds
end

return plrclass
local plrClass = require(PATH_TO_MODULE)

-- Option 2
print(plrClass:GetDiamonds()) -- 100
plrClass:SetDiamonds(9000)
print(plrClass:GetDiamonds()) -- 9000
2 Likes

Sounds like you need to cross script environments from module script to server script.

I do not recommend this for performance reasons but you can try doing this in your player class

function plrClass:SetVarToDiamonds(var)
getfenv(2).Diamonds = self.Diamonds
end

Havenr tested it btw

bro just return the value instead of setting it via a modulescript.
the way your doing is not possible unless it is a value instance.

local Diamonds = Module:SetDiamonds()