How to make a game able to be played if you are invited by someone

So I want to make a game where you can pay to join or you can get a code from someone that already payed to join. For example, if someone payed robux, they can play the game forever, but they could also send a code invite to only 1 person and that person that got invited could invite someone else to play the game. If you know how to this. Please reply, thank you :blush:

For the codes you could assign each player a random code that they could change at any time, (make sure it is not the same as another player’s code) and then save it. Then you could make a gamepass in your game, and if somebody owns the gamepass they would either be sent to a reserved server, and if they don’t own the gamepass they would either be kept in a main server until they entered the code.
For the code prompt I would make it so they have to enter a player’s name or userid and their code, and teleport them to one of the reserved servers if they get the name and the code right. Since it would require a datastore to check if the code is right I would recommend them only being able to submit a code every ten seconds.

Edit: instead of using codes, people with the gamepass should be able to enter a player’s user id, and if that userid is valid you could save some data to the userid that says that the player doesn’t have to be kicked. When a player with the gamepass changes who they allow in, you can call :RemoveAsync() on the old id.