Argument 2 missing or nil

trying to save the team a player is on and it won’t save


The Variable TEAM gets set once the player has a team

1 Like

what is the variable TEAM? It says its nil

1 Like

i said the variable TEAM is The Players Team Once One Is Assigned

1 Like

the line of code defining that? Why would you need to save a team anyway?

1 here


image

2 because it is an important feature for the game i am creating

1 Like

Okay, i see.
Can you provide the full script so i can help perhaps?

1 Like

1 Like

The error means the second argument you are passing in is missing or nil, since you are inputting the variable “TEAM” into the second argument it means it is not missing, but instead the value is nil. I suggest looking through your code and finding out why the value is nil, maybe use print statements to check the value of the TEAM variable before passing it into the SetAsync function.

1 Like

This is because team doesn’t really exist in the other function, Is it because you commented it out? Because I see you did.

no, the commented out stuff is an attempt using stuff server storage but i just was lazy and didn’t remove it completely

1 Like

Instead of using team, try using the result variable

1 Like

Instead of using team, try using the result variable because the team is nil.

Wait im so blind sorry

1 Like

if i use the result variable it won’t work if the player is joining for the first time and has no result

  • that is in the join function
1 Like

I suggest making a table, and putting in the each player who the randomteam() got called on and instead of a global team variable, getting the team variable from that table instead.

1 Like

can you give me an example? I’m a little confused on how to do what you are suggesting

1 Like

Yeah i confused myself with how i formulated it.

So, 1) make a table, ex: local teamPlayers = {}
2) in the randomTeam function, we will do something like: teamPlayers[plr] = randomTeam.Name
3) when saving, we do something like: local Team = teamPlayers[plr]
and then save that instead

it seemed like it worked but then i joined a different team so i don’t think it works
(To Know If It Works I Have To Get A Team And I Leave And Rejoin And Am On That Team At Least 5 Times In A Row Start of Testing To Finish)

Well, the result gives a name, you do

if result then
      plr.Team = Teams:FindFirstChild(result)
end

it seems like it works but i keep getting this

1 Like

can you copy and paste the script in here?
I want to test in studio