ok, try this:
local blip = {}
addEventHandler('onPlayerSpawn',root, function(_, _, _, _, theTeam)
if (not isElement(blip[source])) then blip[source] = createBlipAttachedTo(source) end
local r, g, b = getTeamColor(theTeam)
setPlayerNametagColor(source, r, g, b)
setBlipColor(blip[source], r, g, b, 255)
end)
setTimer(function()
for source,b in pairs(blip)do
if not isElement(source) then
destroyElement(b)
blip[source] = false
end
end
end,10000,0)