game.Players.PlayerAdded:Connect(function(plr)
if not plr:IsFriendsWith(OwnerId) then
plr:Kick("You don't have permission to join this server!")
end
end)
Replace the OwnerId with the reserved server owner’s ID. This script will basically checks if the player joined is friended with the server owner.
Edit: Thanks to @Forummer for reminding me. Changed .IsFriendsWith() to :IsFriendsWith().
I have developed two modules that can do this, I will keep them private, but I can explain the methods I used.
So from what i undestand, what you are trying to archive is letting peoples (user friends) join a reserved server when it has already been created.
The first method you could use would be with the datastore service , you could store the player id or a short randomly generated code that contains the reserved server code. With this code you could then teleport the user in the reserved server.
Another method would be to use Cross-Server Messaging, you could send a request with the id of the player or a pre-defined random string and then wait if another server responds positively by returning this code. Note however that to use this method you must first communicate the code to the new reserved server itself because you can not access it in it.
If you want to make it friend only or add a option to set the server friend only then you could use @Forummer and @Maytidis_good answer to verify if the user is friend with the owner before teleporting him in the reserved server.