Modernize all methods that use player objects which aren't related to in-game data

For a while, a lot of our methods concerning user data referenced users by their Player instance. More recently, thanks to @TheGamer101 and @Seranok, our newer methods (e.g. GroupService members & GetFriendsAsync) reference users by their UserId. The benefit of this is that these methods can be used for players who aren’t in-game, while the older methods are restricted to in-game players. As I mentioned in this thread, it’d be great if this could change.

Methods that need to be updated

  • MarketplaceService:PlayerOwnsAsset(Player, assetId) → MarketplaceService:UserOwnsAsset(userId, assetId)
  • Player:GetRankInGroup(groupId) → GroupService:GetUserRankInGroup(userId, groupId)
  • Player.GetRoleInGroup(groupId) → GroupService:GetUserRoleInGroup(userId, groupId)
  • Or, if the above data is easy to get at the same time, combine into a single method that returns both
  • Player:IsInGroup(groupId) → GroupService:UserIsInGroup(userId, groupId)
  • Deprecate GamePassService:PlayerHasPass(Player, assetId)
  • Wiki page already encourages PlayerOwnsAsset, but it’s not technically deprecated yet
  • BadgeService:UserHasBadge(userId, badgeId)
  • Remove requirement that user has to be in-game

Potential need for change:

  • Player:IsFriendsWith(userId) → Players:IsUserFriendsWith(userId, userId)
  • Can’t really think of why this would be needed when neither user is in-game, but maybe someone else has a use case

Should not change:

  • AssetService:CreatePlaceInPlayerInventoryAsync(Player, …)
  • Developers shouldn’t be able to spam users’ inventories with places when they’ve never even joined their game
16 Likes

Is it also possible for BadgeService:UserHasBadge to work locally (for stuff like badge tracker UI)? Unless there’s a big reason why it’s blocked in LocalScripts currently.

1 Like

Can you provide specific use cases for calling these methods on users who aren’t in the game? Have you been unable to add some functionality to your game because of these restrictions?

I bet one of the main moments when developers will run into issues is when the game has to process something right after the player has left. I’m not entirely sure whether these methods will still return if you captured the player instance beforehand, but I would not hold such behavior as intended.

Several are useful for cross-server stuff like checking if a friend is online in the place by iterating through a datastore table of online UserIds.

The group ones are useful for pretty much any group related place as we may want to get a certain players latest rank for display in a gui if they’re at the top of an in-game leaderboard, etc etc