Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I prevent group service from erroring?

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!

2 comments

0

Can you paste the exact error code?

0

20:51:32.165 - GroupService:GetGroupInfoAsync() failed because HTTP 0 (HTTP 404 (HTTP/1.1 404 NotFound))

1 answer

✓ Accepted answer

Use pcalls to keep the script from stopping when the Game Creator's ID is not a Group ID and GroupService errors.

This discussion is preserved as it was. New answers, comments, and votes are closed.