I am currently trying to make a script that finds the creator of a game. That can be done by doing game.CreatorId
, but if the script is running under a group, it will give the group ID.
What I am currently trying to accomplish is finding who the creator of the game is. I have the following script:
local plridN = game.CreatorId local plrid = tostring(plridN) --The creator's ID local groupid = plrid --If the game is running under a group, the creator's ID will be a group number local group = game:GetService("GroupService"):GetGroupInfoAsync(groupid) local owner = group.Owner if owner ~= nil then print(owner.Id) --Prints the group owner's ID number elseif owner == nil then print(plridN) --Prints the game owner's (because that number is not a group) ID number end
In the script, what it is doing is finding the game's creator's ID and then checking if it is a valid group. However, what is happening is if it isn't a group id, it errors on this line:
local group = game:GetService("GroupService"):GetGroupInfoAsync(groupid)
How can I prevent that line from erroring if it isn't a group?
Thanks in advance!
Use pcalls to keep the script from stopping when the Game Creator's ID is not a Group ID and GroupService errors.