ModuleScript between Server and Client

ModuleScripts are accessable from Server and Client via require()

My issue is that the localscript cant detect changes that are made by the server
My Table: jwnqe = {}
(Normally contains a random generated string. Like in the picture below)
image
trying to print the whats in side the table with a local script will result in nil
image

ModuleScript:

module = {
tt13 = {},
h3i2u = {},
jwnqe = {},
qwjekweq = function()
local jk123ji = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
for i = 1, math.huge do
	wait(1)
	local qweuioqe = ""
	for i = 1, 24 do
	if i == 5 then
	qweuioqe = qweuioqe.."-"
	end
	if i == 9 then
	qweuioqe = qweuioqe.."-"		
	end
	if i == 13 then
	qweuioqe = qweuioqe.."-"	
	end
	if i == 17 then
	qweuioqe = qweuioqe.."-"	
	end
	if i == 21 then
	qweuioqe = qweuioqe.."-"	
	end
    if i ~= 5 or i ~= 9 or i ~= 13 or i ~= 17 or i ~= 21 then
	local a = math.random(1,#jk123ji)
	qweuioqe = qweuioqe..jk123ji[a]
	module.tt13 = qweuioqe
end
end
	local asidha1913 = ""
	for i = 1, 24 do
	if i == 5 then
	asidha1913 = asidha1913.."-"
	end
	if i == 9 then
	asidha1913 = asidha1913.."-"		
	end
	if i == 13 then
	asidha1913 = asidha1913.."-"	
	end
	if i == 17 then
	asidha1913 = asidha1913.."-"	
	end
	if i == 21 then
	asidha1913 = asidha1913.."-"	
	end	
    if i ~= 5 or i ~= 9 or i ~= 13 or i ~= 17 or i ~= 21 then
	local b = math.random(1,#jk123ji)
	asidha1913 = asidha1913..jk123ji[b]
	module.h3i2u = asidha1913
	end
	end
	
	local iasdhz = ""
	for i = 1, 24 do
	if i == 5 then
	iasdhz = iasdhz.."-"
	end
	if i == 9 then
	iasdhz = iasdhz.."-"		
	end
	if i == 13 then
	iasdhz = iasdhz.."-"	
	end
	if i == 17 then
	iasdhz = iasdhz.."-"	
	end
	if i == 21 then
	iasdhz = iasdhz.."-"	
	end
    if i ~= 5 or i ~= 9 or i ~= 13 or i ~= 17 or i ~= 21 then
	local a = math.random(1,#jk123ji)
	iasdhz = iasdhz..jk123ji[a]
	module.jwnqe = iasdhz
	end
end	
end
return module.tt13, module.h3i2u, module.jwnqe[1]
end
}

return module

Script:

local req = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))
local remotekey = ""

function sdas()
local data1 = req.qwjekweq()
end

spawn(function()sdas()end)

wait(4)
print("start")
while wait() do
game.Workspace.Name = req.tt13
remotekey = req.jwnqe
print("[Server]Key: "..remotekey)
end

LocalScript:

local Button = script.Parent.GetMoney
local req = require(game:GetService("ReplicatedStorage"):FindFirstChild("ModuleScript"))
local player = game.Players.LocalPlayer

remotekey = ""

Button.MouseButton1Click:Connect(function()
print(req.jwnqe[1])
end)

Is there any fix for this?

1 Like

That’s because you are executing function qwjekweq on the server, therefore the changes will not replicate to the client. Client server communication is not possible via module scripts because if you require a module script on the server and on the client, they are different instances.

2 Likes

A ModuleScript isn’t a table that can be used in client → server communication or something that can share constantly updating information from within itself. It’s more like reusable code that you can use in diffrent scripts. Think of it like a function you can use in any script. When you require a ModuleScript you’re loading the code within it, more specifically, what it returns.

2 Likes

You actually can use it as a global table but not in client server communication. That’s because if you require a module script from one place on the server and from another place on the server, you are referencing one table actually.

Misworded, let me just edit that for any future readers. Thanks