I tested the whole script, and it worked, i don't understand it's not even in the script you posted, because i just tested it and it worked.
Here that's what i tested:
local skinsForEMI = {183,158,159,160,162,132,136} addEvent("buttonClicked",true) gamemodeStarted = false playersForIMI = {} playersForPOL = {} function setcolor(playerSource) outputChatBox("cona") setPlayerNametagColor(playerSource, 255, 10, 40) end addCommandHandler("nametagcolor", setcolor) function joinHandler(equipa) if (gamemodeStarted == false) then if(equipa == 'imigrante') then table.insert(playersForIMI, source) --setPlayerNametagColor(source, tonumber(205), tonumber(133), tonumber(63)) elseif(equipa == 'police') then table.insert(playersForPOL, source) --setPlayerNametagColor(source, 30, 144, 255) else local numberOfTeam = math.random(2) if numberOfTeam == 1 then table.insert(playersForIMI, source) else table.insert(playersForPOL, source) end end end end addEventHandler("buttonClicked", root, joinHandler) function playerJoin () local name = getPlayerName(source) for i, v in ipairs(getElementsByType("player")) do if (v ~= source) then outputChatBox("[" .. name .. "] has joined the server", v, 255, 64, 64) end end end addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin ) function destroyBlipsWhenPlayerLeavesServer ( quitType) local name = getPlayerName(source) outputChatBox("[" .. name .. "] has left the server [" .. quitType .."]", getRootElement(), 255, 64, 64) if source then local attacheds = getAttachedElements ( source ) if ( attacheds ) then for k,element in ipairs(attacheds) do if getElementType ( element ) == "blip" then destroyElement ( element ) end end end end end addEventHandler ( "onPlayerQuit", getRootElement(), destroyBlipsWhenPlayerLeavesServer ) function colocarDeNoite () setTime ( 1, 0) --setWeather ( 22 ) end addEventHandler ( "onResourceStart", getRootElement(), colocarDeNoite) segundos = 30 timerEnabled = false gamemodeStarted = false local mostrou = false addEvent("checkTwoPlayersOnMode", true) function checkTwoAndNotStartedRunIT () if gamemodeStarted == false then if timerEnabled == false then if(getPlayerCount() >= 1) then setTimer(escreve, 200, 1) triggerClientEvent("canShowGUISPAWN",getRootElement()) mostrou = true else outputChatBox("NOTE: This gamemode need at least 2 players online to start!", source) end else setElementData(source,"secondsRemaining",tostring(segundos)) triggerClientEvent ( source, "showDX", source ) triggerClientEvent(source,"canShowGUISPAWN",source) end else outputChatBox("You will need to wait the gamemode to finish, sorry", source) end end addEventHandler("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT) function escreve () timerEnabled = true for i,v in pairs(getElementsByType("player")) do setElementData(v,"secondsRemaining",tostring(segundos)) triggerClientEvent ( v, "showDX", v ) if(mostrou ~= true) then triggerClientEvent(v,"canShowGUISPAWN",v) end end setTimer(countDown,1000,30) end function countDown() segundos = segundos -1 for i,v in pairs(getElementsByType("player")) do setElementData(v,"secondsRemaining",tostring(segundos)) end if segundos == 3 then triggerClientEvent("hadChosenTeam", getRootElement()) end if segundos == 0 then triggerClientEvent ( "hideDX", getRootElement() ) triggerClientEvent("hideSpawnGUI", getRootElement()) timerEnabled = false gamemodeStarted = true if(#playersForIMI==#playersForPOL or #playersForIMI == #playersForPOL + 1 or #playersForPOL == #playersForIMI + 1) then spawn() else outputChatBox("---Gamemode will run auto-balance---", getRootElement(), 255, 64, 64) autobalance() end end end function onStart () timerEnabled = false if(getPlayerCount() >= 2) then removeEventHandler ("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT ) setTimer(escreve, 1500, 1) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart ) function autobalance() if(#playersForIMI - #playersForPOL >= 2) then local sync = false local dif = #playersForIMI - #playersForPOL if(dif % 2 == 0) then while(sync ~= true) do if(#playersForIMI ~= #playersForPOL) then table.insert(playersForPOL, playersForIMI[#playersForIMI]) table.remove(playersForIMI, #playersForIMI) setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP ) outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64) else sync = true end end spawn() else while(sync ~= true) do if(#playersForIMI ~= #playersForPOL + 1) then table.insert(playersForPOL, playersForIMI[#playersForIMI]) table.remove(playersForIMI, #playersForIMI) setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP ) outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64) else sync = true end end spawn() end elseif(#playersForPOL - #playersForIMI >= 2) then local sync = false local dif = #playersForPOL - #playersForIMI if(dif % 2 == 0) then while(sync ~= true) do if(#playersForPOL ~= #playersForIMI) then table.insert(playersForIMI, playersForPOL[#playersForPOL]) table.remove(playersForPOL, #playersForPOL) setPlayerTeam ( playersForIMI[#playersForIMI], team_immigrantsSP ) outputChatBox(">>Auto-balance system changed your team!", playersForIMI[#playersForIMI], 255, 64, 64) else sync = true end end spawn() else while(sync ~= true) do if(#playersForPOL ~= #playersForIMI + 1) then table.insert(playersForIMI, playersForPOL[#playersForPOL]) table.remove(playersForPOL, #playersForPOL)