Concerns with Accessing a Module

With the new Accurate Play Solo feature, there are some conflicts with accessing a module. When accessing a module via the client, the client has it’s own thread of the module and so does the server.

However, when accessing a module via the command bar, the command bar creates it’s own thread of the module and creates conflicts on the server or the client :expressionless:

If you haven’t noticed this behavior, feel free to try this out

1.) Create a module in ReplicatedStorage
2.) Name it “Module” and paste this code in it

local ModuleValue = 0
local module = {}
function module:SetValue(Value)
ModuleValue = Value
end
function module:PrintValue()
print(ModuleValue)
end
return module

3.) Create a script in StarterGui
4.) Paste this code in it

local Module = require(game:GetService("ReplicatedStorage"):WaitForChild("Module"))
Module:SetValue(10)
Module:PrintValue()

5.) Create a script in ServerScriptService
6. Paste this code in it

local Module = require(game:GetService("ReplicatedStorage"):WaitForChild("Module"))
Module:SetValue(50)
Module:PrintValue()

7.) Play the server and paste this code in the command bar in a single line

Module = require(game.ReplicatedStorage.Module); Module:SetValue(500); Module:PrintValue()

All the printed values should be different even if the command bar is either client-sided or server-sided.

I’m not sure if this is normal behavior, but shouldn’t the command bar be able to access the thread of the client? (It makes testing the module easier)

The command bar is separate from the client and server environments. The behavior you’re experiencing is normal

4 Likes

You can indent your code by doing

Since I failed to demonstrate it with text three times, you can do it like so:

1 Like

Lol :slight_smile: sorry I help out some people I know with their programming and now when I see code that is not indented it just annoys me.

1 Like

Another tip regarding modules in the command bar. Because require caches the result, it makes it hard to test modules from the command bar. If you’re trying to test modules via the command bar, you can simply clone the module each time you require it from the command bar:

local m = require(game.Wherever.MyModule:Clone())
3 Likes