I am trying to make a script for a round based game where two people get picked to become Presidential nominees and debate, this is the script that chooses the to players and puts them on the two different teams (Democrat and Republican) but it stops working midway through the '_G.Teams' function.
local Teams = game:GetService("Teams")
local blueParty = Teams["Democratic Party"]
local redParty = Teams["Republican Party"]
local playersOnRedTeam = game:GetService("Teams")["Republican Party"]:GetPlayers()
local playersOnBlueTeam = game:GetService("Teams")["Democratic Party"]:GetPlayers()
local function selectPlayer()
local players = game.Players:GetPlayers()
local selected = players[math.random(1,#players)]
return selected
end
_G.Teams = function()
local randomPlayer = selectPlayer()
local selectedTeam = math.random(1,2)
if randomPlayer and randomPlayer.Character then
if randomPlayer.Team == redParty then
print("We can't pick this player!")
wait()
selectPlayer()
wait()
_G.Teams()
elseif randomPlayer.Team == blueParty then
print("We can't pick this player!")
wait()
selectPlayer()
wait()
_G.Teams()
else
if selectedTeam == 1 then
if #playersOnRedTeam >= 1 then
randomPlayer.Team = blueParty
else
randomPlayer.Team = redParty
end
end
end
end
end

9 comments
what exactly is 'midway', are there any errors? Do you know exactly which line? If not, did you try printing tactic, printing few lines and checking whether it prints?
Well, keep your variable for playersOnRedTeam and playersOnBlueTeam inside _G.Teams. Because, the variable will be updated once when the game starts, i.e., if you print them, it will print 0. Just put it in your _G.Teams().
I not getting any errors, its just nothing will print (or even work) past line 17
Using _G is heavily discouraged. Do not use it.
well is there anyway I can use other forms of global variables?
Can't you use a local variable? Also why you bring politics to roblox?
@Oxiousately Did you test the code after you put the two variables inside the function
@BestCreativeBoy yes, although it didn't work it was useful to the script