How to check if a player is a group leader for the current game?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am trying to make a game detect if a player is the owner of a group game. I am selling this hence why I cant hard code it.

  1. What is the issue? Include screenshots / videos if possible!

I can run the program just fine but it doesnt run any of the event. I even put a print statement after the chatted event but it prints nothing even after the if statements.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I got the idea from this dev forum post API to check if user is owner from game (or group owner)? and it looks basically like mine but cant seem to find the issue.

Program Code

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local PlaceInfo = game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId)

script:WaitForChild("AdminCommand").Parent = ReplicatedStorage
script:WaitForChild("OpenUI").Parent = ReplicatedStorage

local DataSaving = require(script:WaitForChild("DataSaving"))

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local message = string.lower(msg)
		if message == ":adminpanel" then 
			if PlaceInfo.Creator.CreatorType == Enum.CreatorType.Group then
				print("group game")
				local GameOwner = game:GetService("GroupService"):GetGroupInfoAsync(PlaceInfo.Creator.CreatorTargetId).Owner.Id
				if GameOwner == player.UserId or DataSaving:GetData(player, "IsAdmin") then
					ReplicatedStorage.OpenUI:FireServer()
				else
					print "not creator"
				end	
			else
				print("not a group game")
				if player.UserId == game.CreatorId or DataSaving:GetData(player, "IsAdmin") then
					ReplicatedStorage.OpenUI:FireServer()
				else
					print "not creator"
				end
			end
		else
			print("message not found")
		end
	end)
end)

Have you tried using :GetRankInGroup()

For example,

game.Players.PlayerAdded:Connect(function(player)
	if player:GetRankInGroup(31283721) == 255 then
		print("This player is the group owner")
	end
end)

I don’t know if this is what you’re looking for, but you could change 255 to another group rank number.

I said in the post that I can not hard code it. I need to get the group ID the current place too even do that.

You can try this code. This should get the ID of the group owner if the game is under a group. Let me know if it works. Also, good luck with your project!


local gameOwner = nil
if game.CreatorType == Enum.CreatorType.Group then
    gameOwner = game:GetService("GroupService"):GetGroupInfoAsync(PlaceInfo.Creator.CreatorTargetId).Owner.Id
else
    gameOwner = game.CreatorId
end

The variable ‘gameOwner’ should end up being the owner’s Roblox UserId.

I have that implemented in my code I thought. Did I not input it correctly?