Does anyone know how to change a string value for all scripts?

I made this part of my script to where when you click the button, the race value will change to 1 instead of 0, but when i start my game and click the button it gives me 0 instead of 1, same thing when i try to call the value from a server script or another local script, it still gives me 0. What im trying to do is make it so when the value changes to 1, every script is going to see it as 1.

local script

HumanRace.MouseButton1Click:Connect(function()
	Racev.Value = 1 -- This is what i thought i would use to change the value
	print(Racev.Value) -- but instead of giving me 1 it gives me 0
end)

Screenshot 2026-04-10 225245

LocalScripts work on the client, meaning that nothing a LocalScript does will happen on the server. You should use a RemoteEvent to communicate with the server and have the server set Racev’s value to 1.

3 Likes

Use a RemoteEvent and have the value be changed by a server script! Try it and tell me what happens

2 Likes

it did change the value for the string, but im getting the same result on the output

There is a quick way to achieve this.
Roblox provides global table called “_G” which lets you access and modify it from every script in the game.
It depends if you are on client or server side.

LocalScript1

_G["var"] = 1

LocalScript2

task.wait(1)
print(_G["var"])

But it is not very much recommended and pretty much a little outdated now.
And if it contains critical data, it would be a lot easier for exploiters to cheat because they can simply read and change the values.

I would recommend you to combine 1 LocalScript and whatever the amount of ModuleScripts you need but eventually it’s personal preference and how you decide how you would organize and structure your game.

If you have questions or I have a mistake feel free to reply :grinning_face:

i just tried it and all i got was just nil, plus i wasn’t able to change the value since it would jus index nil, but if i did anything wrong please tell me because i kinda didn’t understand what i was supposed to put

local script 1

local racev = workspace.R6.Race
_G[racev.Value] = 1

local script 2

print(_G[racev.Value])

result
Screenshot 2026-04-11 133730

When there are 2 LocalScripts, both of them run independently from one another, in another words, they all start at the same time - sometimes the first script is started first, sometimes the second. The difference is tiny but it exists. That’s the core issue with _G I actually forgot to mention.
If you add the

task.wait(1)

It should work.
But again I recommend you using ModuleScripts as it would make this a lot easier both for debugging and future weird errors :blush:

1 Like

i got the same result from the code you gave me, and if possible can you give me some tips for Module Scripts because im still trying to learn them

Modules are very easy to use, I recommend checking out gnomeCodes video on it. Please be aware this video is mean’t for beginners so you might face some things your already know.

1 Like

Great!

Nothing stops you from writing the whole game logic into one gigantic script but that’s is the worst case scenario i have been to and it’s worse than a headache.

Basically a module script acts like a puzzle you connect to another script.

When you require module script you “connect” them together.

Have a look at this one:

local table = {}

table.value = 1

print(table.value) -- prints 1

table.value = 2

print(table.value) -- prints 2

And a LocalScript and ModuleScript
LocalScript:

-- basically saying "connect module script as it was codes of lines and append them here
local ModuleScript = require(script.Parent.ModuleScript)

print(ModuleScript.value) -- prints 1

ModuleScript.value = 2

print(ModuleScript.value) -- prints 2

ModuleScript:

local module = {}

module.value = 1

return module

–
These are exactly the same systems and both should work.

But just imagine you are making gigantic roblox game and have to include each game character’s abilities such as health, power, etc..
It should be a lot easier if you create a folder and inside it with multiple module scripts, each include values and properties for one character than having one long script with hundreds of lines of code.

Here 2 awesome tutorials recommend you watching:

2 Likes

Thanks for the help and advice ill be sure to start using module scripts more, especially for things like this

1 Like

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