Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I prevent group service from erroring?

Asked by
Kev_nn 4
5 years ago

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!

0
Can you paste the exact error code? Pojoto 329 — 5y
0
20:51:32.165 - GroupService:GetGroupInfoAsync() failed because HTTP 0 (HTTP 404 (HTTP/1.1 404 NotFound)) Kev_nn 4 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question