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

How do I make it so if the GetGroupInfoAsync() fails that it will move on and choose a new id?

local Button = script.Parent
local frm = script.Parent.Parent.Parent.Group
frm.Visible = false
function onClick()
	local rank=frm.Ranks
	local max = script.Parent.Parent.MaxTextBox.Text
	local min = script.Parent.Parent.MinTextBox.Text
	local frm = script.Parent.Parent.Parent.Group
	local Url = frm.Url
	local desc = frm.Desc
	local name = frm.name
	local owner = frm.Owner
	local img = frm.ImageLabel
	--local memberCount = frm.memberCount
	frm.Visible = true
	print(max)
	print(min)
	repeat 
	local groupId = math.random(min,max)
	print(groupId)
		local group = game:GetService("GroupService"):GetGroupInfoAsync(groupId)
	wait(0.006)
	if group ~= nil then	
	if group.publicEntryAllowed == true then 
	if group.Owner == nil then owner.Text = "No One!"
	Url.Text = 'https://www.roblox.com/groups/'..groupId.."/"..group.Name
	desc.Text = group.Description
	img.Image = group.EmblemUrl
	name.Text = group.Name
	--memberCount.Text = "Members:" .. group.MemberCount
	for _, role in ipairs(group.Roles) do
   		rank.Text = ("Rank " .. role.Rank .. ": " .. role.Name)
	end
	
	
	wait(0.5) 
				else groupId = math.random(min,max) and owner.Text == group.Owner.Name
					
				end
			end
		end

	until group.Owner == nil and group.publicEntryAllowed == true
end
Button.MouseButton1Click:connect(onClick)

this is the code but i changed it a bit so I don't know if it works like it did originally.

Right now it stops whenever it fails because of HTTP 404 (Not Found)

3 comments

0

(line 21 is where it errors if it wasn't obvious)

0

(BTW it also doesnt fail all of the time

0

I just realized there may be a better way to do this than GetGroupInfoAsync()

1 answer

Using pcall(function() ignores errors

local Button = script.Parent
local frm = script.Parent.Parent.Parent.Group
frm.Visible = false
function onClick()
	local rank=frm.Ranks
	local max = script.Parent.Parent.MaxTextBox.Text
	local min = script.Parent.Parent.MinTextBox.Text
	local frm = script.Parent.Parent.Parent.Group
	local Url = frm.Url
	local desc = frm.Desc
	local name = frm.name
	local owner = frm.Owner
	local img = frm.ImageLabel
	--local memberCount = frm.memberCount
	frm.Visible = true
	print(max)
	print(min)
	repeat 
		local groupId = math.random(min,max)
		print(groupId)
		local group = pcall(function() game:GetService("GroupService"):GetGroupInfoAsync(groupId)
		end)
		wait(0.006)
		if group ~= nil then    
			if group.publicEntryAllowed == true then 
				if group.Owner == nil then owner.Text = "No One!"
					Url.Text = 'https://www.roblox.com/groups/'..groupId.."/"..group.Name
					desc.Text = group.Description
					img.Image = group.EmblemUrl
					name.Text = group.Name
					--memberCount.Text = "Members:" .. group.MemberCount
					for _, role in ipairs(group.Roles) do
						rank.Text = ("Rank " .. role.Rank .. ": " .. role.Name)
					end


					wait(0.5) 
				else groupId = math.random(min,max) and owner.Text == group.Owner.Name

				end
			end
			end
	until group.Owner == nil and group.publicEntryAllowed == true
end
Button.MouseButton1Click:connect(onClick)


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