i'm back again, with the same question sorta, but how do i make my code into a modulescript form, i'm reading about modulescripts but its not helping because no one is providing a example with my code and not codes that are saying "HI" in a input.
I dont know were to start, where do i put what?, because i have a feeling whats causing my game to break is these garbage _G functions, and i need to eliminate those as soon as possible.
So if you would be kind enough to provide, a sample of what i should do with my code i am about to show you.
function getRandomMode()
local gameModes = {_G.eliminationRound, _G.teamSwapRound, _G.controllerRound,}
local randomSlot = math.random(1, #gameModes)
local randomMode = gameModes[randomSlot]
roundType = gameModeNames[randomSlot]
_G.announce("Round chosen: "..gameModeNames[randomSlot], Color3.new(0, 0, 0), 2)
wait(1)
local description = descriptions[randomSlot]
for index, text in pairs(description) do
_G.announce(text, Color3.new(0, 0, 0), 2)
wait(1)
end
return randomMode
end
function getRandomMap()
local gameMaps = game.Lighting.Maps:GetChildren()
local randomMap = gameMaps[math.random(1, #gameMaps)]
_G.announce("Map chosen: "..randomMap.Name, Color3.new(0, 0, 0), 2)
return randomMap
end
function getRandomSpawn(teamColor)
if (workspace:findFirstChild("Map")) then
local spawns = {}
if (teamColor == game.Teams.Red.TeamColor) then
spawns = workspace.Map.Red:GetChildren()
else
spawns = workspace.Map.Blue:GetChildren()
end
local spawn = spawns[math.random(1, #spawns)]
return spawn
end
return nil
end
Exactly how do i eliminate these _G functions on my code, thank you for helping.

6 comments
so in my code i would replace the _G with local module =(script.Module) would i need to put anything else in the workspace.
you need to use the keyword require, and the code I have in "Example" is the code that would be in a modulescript at the location you use require on.
Also important to note that Module Scripts only return a single value. However, it is also important to note that that value can be anything.
ok i get the purpose of modulescript, but how do i type it in my script, this example you gave me too me is completely different from my script that is why is said could someone make a example with my script because im still scratching my head and asking how do i convert that in to my script, i was going to type local module.GameModes = {.eliminationRound,} like that but with out the _G
Part of being a scripter is not having everything handed to you. Go into studio and figure it out. I showed you the setup for something in the _G table, and how to put it in a module instead. The only difference between our scripts is the contents of our tables.
In fact, this is the second question you've posted about this, and the other one was filled with answers that showed you how to use modules. If you understand that _G is just a table, and you understand how modules work, then the only thing left is to do it, not to ask someone to do it fot you.