Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I have Int Values constant through different scripts?

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?

1 comment

0

abide by filtering enabled rules

1 answer

✓ Accepted 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

0

However, if you wanted to change _G.Value, you would have to change it in a server script

0

I put _G.Value = 1 in the server script but in my local script it comes out as 'nil'

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.

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"

0

actually make it "repeat wait() until _G.Value ~= nil"

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.

0

Now whenever you change module.Value in a server script and you call it again in the local script, it will change

0

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.