So I am trying to make a game with teams, and currently, there is a GUI that lets you select a team, and then increases a number value in server storage. If the value is over the limit, you can't select that class.
each team has their own value, and each team has their own class limit.
I am trying to make a script that detects if your team is changed, it will switch your class values (if you are any of the two limited classes) to the other team.
I do not get any errors, and the script seems to work, but if I switch teams twice, then the shade/medic value goes up twice, and if I switch teams three times, then the shade/medic value goes up three times!
This is the script
function checkteam(player)
if player.Team == team1 then
if player.stuff.Class.Value == "Medic" then
Team1MedicLimit.Value = Team1MedicLimit.Value + 1
Team2MedicLimit.Value = Team2MedicLimit.Value - 1
end
if player.stuff.Class.Value == "Shade" then
Team1ShadeLimit.Value = Team1ShadeLimit.Value + 1
Team2ShadeLimit.Value = Team2ShadeLimit.Value - 1
end
elseif player.Team == team2 then
if player.stuff.Class.Value == "Medic" then
Team2MedicLimit.Value = Team2MedicLimit.Value + 1
Team1MedicLimit.Value = Team1MedicLimit.Value - 1
end
if player.stuff.Class.Value == "Shade" then
Team2ShadeLimit.Value = Team2ShadeLimit.Value + 1
Team1ShadeLimit.Value = Team1ShadeLimit.Value - 1
end
end
end
wait(1)
for _, team in pairs(teams:GetTeams()) do
team.PlayerAdded:connect(function(player)
player:GetPropertyChangedSignal("Team"):Connect(function()
checkteam(player)
end)
end)
end
