Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I have Int Values constant through different scripts?

Asked by 4 years ago

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?

0
abide by filtering enabled rules Fifkee 2017 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
However, if you wanted to change _G.Value, you would have to change it in a server script Brandon1881 721 — 4y
0
I put _G.Value = 1 in the server script but in my local script it comes out as 'nil' finn383 2 — 4y
1
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. killerbrenden 1537 — 4y
0
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" Brandon1881 721 — 4y
View all comments (4 more)
0
actually make it "repeat wait() until _G.Value ~= nil" Brandon1881 721 — 4y
0
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. Brandon1881 721 — 4y
0
Now whenever you change module.Value in a server script and you call it again in the local script, it will change Brandon1881 721 — 4y
0
Now whenever you change module.Value in a server script and you call it again in the local script, it will change Brandon1881 721 — 4y
Ad

Answer this question