Hello. I was wondering what the best way to set up my local script would be regarding the “GAME_OBJS” variable. I want to be able to use the variable for any of my functions needed but is it necessary to share a variable with all of the functions or just make another variable inside of each function so that it has essentially the same variable but just used to that one function
Method 1:
--LocalScript
local contents = {}
["TEST"] = function(bool, information)
local GAME_OBJS;
if bool == true then
if contents["GAME"] == nil then
contents["GAME"] = {
GAME_OBJS = {}; --ALL of the game objs.
game_Functions = {--ALL of the game functions.
["FUNCTION1"] = function(bool)
GAME_OBJS["Counter1"] = 0;
while GAME_OBJS["Counter1"] == 0 do
wait(0.2)
end
end,
}
contents["GAME"].game_Functions["FUNCTION2"] = function()
GAME_OBJS["TopBar1"].Size = UDim2.new(0,0,0.05,0)
GAME_OBJS["TopBar2"].Size = UDim2.new(0,0,0.05,0)
end
}
end
GAME_OBJS = contents["GAME"].GAME_OBJS
GAME_OBJS.INFO = information
local info = GAME_OBJS.INFO
if info["Command"] ~= nil then
--Run a command then.
if info["Command"][1] ~= nil then
if contents["GAME"].game_Functions[info.Command[1]] ~= nil then
contents["GAME"].game_Functions[info.Command[1]](info["Command"][2])
end
else
if contents["GAME"].game_Functions[info.Command] ~= nil then
contents["GAME"].game_Functions[info.Command]()
end
end
end
end
end,
Method 2:
--LocalScript
local contents = {}
["TEST"] = function(bool, information)
if bool == true then
if contents["GAME"] == nil then
contents["GAME"] = {
GAME_OBJS = {}; --ALL of the game objs.
game_Functions = {--ALL of the game functions.
["FUNCTION1"] = function(bool)
local GAME_OBJS = contents["GAME"].GAME_OBJS --**
GAME_OBJS["Counter1"] = 0;
while GAME_OBJS["Counter1"] == 0 do
wait(0.2)
end
end,
}
contents["GAME"].game_Functions["FUNCTION2"] = function()
local GAME_OBJS = contents["GAME"].GAME_OBJS --**
GAME_OBJS["TopBar1"].Size = UDim2.new(0,0,0.05,0)
GAME_OBJS["TopBar2"].Size = UDim2.new(0,0,0.05,0)
end
}
end
local GAME_OBJS = contents["GAME"].GAME_OBJS --**
GAME_OBJS.INFO = information
local info = GAME_OBJS.INFO
if info["Command"] ~= nil then
--Run a command then.
if info["Command"][1] ~= nil then
if contents["GAME"].game_Functions[info.Command[1]] ~= nil then
contents["GAME"].game_Functions[info.Command[1]](info["Command"][2])
end
else
if contents["GAME"].game_Functions[info.Command] ~= nil then
contents["GAME"].game_Functions[info.Command]()
end
end
end
end
end,