Okay so basically I am using the built-in team functions for my gang-system. I've encountered some weird issues with it. The thing is that it works when I execute it with runcode but not at the actual script. I'm trying to check if there is players left in the team and if there is no one, it's supposed to get deleted. Well the script is self-explanatory. Help me please!
I literally have no idea what I am suppose to add, maybe you can point my mistake out?
Thanks in advance
Runcode
createTeam("MTA_TEST_TEAM", 255, 0, 0)
if (countPlayersInTeam(getTeamFromName("MTA_TEST_TEAM")) == 0) then
destroyElement(getTeamFromName("MTA_TEST_TEAM"))
end
Script
addEvent( "onPlayerChangeTeam", true )
function onPlayerChangeTeam(newTeam, oldTeam)
if (countPlayersInTeam(old) == 0) then
destroyElement(old)
end
end
addEventHandler("onPlayerChangeTeam", root, onPlayerChangeTeam)
_setPlayerTeam = setPlayerTeam
function setPlayerTeam ( player, newTeam )
if not player or not newTeam then return false end
local oldTeam = getPlayerTeam(player)
if (oldTeam) then
triggerEvent("onPlayerChangeTeam", player, newTeam, oldTeam)
end
return _setPlayerTeam(player, newTeam)
end