Get owner's UserId if game is a group game?

Hi there! I am trying to make a script that executes something when the owner joins. However when a game is a group game, game.CreatorId returns the groupid.

Is there a way to get the owner from the group when the game is a group game? I mean, the user who gets that owner tag in the playerlist?

Thanks in advance,
Jonas

1 Like

game.OwnerID is a group id in this case. He can’t compare.

I need to get the id from the creator, not from the player. Just to check if someone is the game owner or not.

1 Like

You could use GetGroupInfoAsync using Group Service. This returns a dictionary where you can index to the Owner which gets the player and get the UserId out of that

Thanks! :slight_smile: But, how do I check if the game is a group game?

I would suggest checking player’s rank in the group
I’ll refer to the playerlist script here.

if game.CreatorType == Enum.CreatorType.Group then
      local success, result = pcall(function()
            return player:GetRankInGroup(game.CreatorId) == 255
      end)
      if success and result then
            -- PLAYER IS AN OWNER
      end
end

PS: If you want to check both you can always change it to

local success, result = pcall(function()
      return game.CreatorType == Enum.CreatorType.Group and player:GetRankInGroup(game.CreatorId) == 255 or game.CreatorId == player.UserId
end)
if success and result then
      -- PLAYER IS AN OWNER
end
5 Likes

If you’re looking for a hacky way to do this without using the plr.UserId thing Ruizu suggested you could do.

if plr:GetRankInGroup(ID) == 255 then
-- Code
end

Posted at the same time. Woops

Thanks! But the game isn’t always a group game. :wink:

EDIT: I’m stupid, that solved it, thanks! :wink:

1 Like

You can always compare the IDs if the game.CreateType is an User.

2 Likes

Make sure to mark someones post as the solution so users don’t get confused!!