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

Global Variables, how do they work?

I am attempting to have one script with a boolean variable determine if another script should run.

I seem to be having trouble getting the variable to transfer over though.

This is a basic summary of what I am trying to do. (Rather than throwing my entire block of code at you)

Script 1:

start = true

Script 2:

while true do
	
while start do -- "start" is used here
	-- Blah blah blah, code here.  (Nothing that affects "start")
wait()
end

Is this how I would use non-local variables inside other scripts?

All the scripts that use such things are running when I run my environment (I have a "while true" keeping them running in the background).

However, script 2 never goes through that second while loop.

Anyone have ideas?

Thanks

1 answer

✓ Accepted answer

Say you have _G.Var = true in the server-script 'apple' then you have another server-script called 'Bananas' you can access _G.Var from Bananas since it is Global

In Apples

_G.Var = true

In Bananas

print(_G.Var)

Please upvote my answer if this helped.

1 comment

0

Thanks a lot. I have been messing with global functions and tried to do the same with variables, but I must of messed something up my first try.

This discussion is preserved as it was. New answers, comments, and votes are closed.