Question about modules

Ok so this is gonna be a really simple question, lets say in a module I change a value on a local script, I know that it wont effect the server obv, but will other local scripts that are in the same player be able to see the changes too?

This shouldnt be to hard to answer I believe

3 Likes

Yes, every other reference to the module in that same environment (client/server), even if it’s a different local script will be affected. Shared values are the main reason modules exist.

2 Likes

As long you set things in the client, affected changes will stay in the client. ONLY on that same localscript.

So if you were to have a different localscript to check for a value, it would not detect any changes.

2 Likes

That is not correct.

Script 1:

require(workspace.ModuleScript).t = true

Script 2:

task.wait(1)

print(require(workspace.ModuleScript).t) -- true
2 Likes

I misread the OP’s post and did not account for ModuleScripts, and that’s my mistake.

However, original point still holds. If you change a value with a localscript that is not in a ModuleScript, another localscript will not detect that change.

EDIT:

I am wrong and I accidentally created a server script.

Please discard all of what I said above and below.

What do you mean “change a value”, like a property? If so, those are detected by other local scripts as well.

If you mean changing a variable’s value, that of course will be true because scripts can’t access each others’ environments (unless you use a hack to make the script’s environment global then that will be reflected)

2 Likes

Yes, I meant to change a value like a property.

I did actually test this just now.

-- localscript 1

-- money's original value = 0

money.Value = 2;
-- localscript 2
print(money.Value) -- output: 0

Unless I made a mistake, then that’s the output I received.

1 Like

You have a race condition, script 2 is likely running before script 1. Add a wait.

task.wait(1)

print(workspace.Value.Value) -- 2

I did add a task.wait and it gave me the same output.

Wouldn’t it be hilarious if it turned out I used a server script instead?

If one script is server sided and one is client sided then yes of course it wouldn’t replicate. The changes will replicate to any changes on the same environment. We’re getting off topic, so send a dm if you need help with this.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.