function setTeam()
local account = getPlayerAccount(source) -- gets players account
local team = getAccountData (account, "team") -- gets players team
if (team) and getTeamFromName(team) then
setPlayerTeam(source, getTeamFromName(team)) -- sets players team
end
end
addEventHandler("onPlayerLogin",root,setTeam) -- sets players team on login

function save()
local team = getPlayerTeam(source) -- Gets the players team
local account = getPlayerAccount(source)
if (team) and not isGuestAccount(account) then -- Checks to see if the player is a guest or not
setAccountData(account, "team", getTeamName(team)) --saves team
end
end
addEventHandler("onPlayerQuit", getRootElement(), save) -- saves team on quit