I'm trying to make a value like IntValue = 1 in the Server script so then it makes IntValue also = 1 in a Local Script. How can I do this?
How can I have Int Values constant through different scripts?
1 answer
Instead of using an IntValue, you could use module scripts.
For example,
In a module script (inside ReplicatedStorage):
module = {}
module.Value = 1
return module
In a local script:
local module = require(game:GetService("ReplicatedStorage"):WaitForChild("ModuleScript"))
local value = module.Value
8 comments
However, if you wanted to change _G.Value, you would have to change it in a server script
I put _G.Value = 1 in the server script but in my local script it comes out as 'nil'
You could also use a ModuleScript with values in there and call from there, as when you change it in there, it changes in all the scripts.
It's most likely because the local script is being added in before the server script, so the local script executes slightly earlier than the server script (_G.Value has no value if the server script hasn't executed yet). So simply add a delay in the local script at the top. Maybe something like "repeat wait() until _G.Value"
actually make it "repeat wait() until _G.Value ~= nil"
okok, actually it may not work. I tested it a bit and it seems like _G (in the local script) will not change if the server changes it. So I think you'd have to use module scripts. I edited my answer for that.
Now whenever you change module.Value in a server script and you call it again in the local script, it will change
Now whenever you change module.Value in a server script and you call it again in the local script, it will change
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
abide by filtering enabled rules