#how to detect if player:IsInGroup() is taking too long

1 messages · Page 1 of 1 (latest)

regal coral
#

hi, my loading screen has a check for whether players are in a group or not because it affects what teams and spawns they have access to.

i currently have a timeout check that theoretically should work, but i feel like it's hanging on waiting for a response and so never increments its timeout.

expected behaviour: print 'uh' initially, then print 1, nil - 2, nil - etc. until roblox returns a value or timeout hits 10

actual behaviour: prints 'uh' initially, then either immediately prints 1, true (successful api call) or there is a long delay with no printing until the api returns a value and it prints 1, true

local timeout = 0
print('uh')
local success, failure = pcall(function() repeat timeout += 1 print(timeout, player:IsInGroup(12326302)) task.wait(1) until player:IsInGroup(12326302) ~= nil or timeout == 10 end) --check whether in group before we get to menu so theyre not waiting there

tardy basin
#
-- [[ Player ]]
local Player = game:GetService("Players").LocalPlayer;

-- [[ VARS ]]
local MaxAttempts = 10;
local Attempts = 0;
local Success, Result;

-- [[ WHILE NOT SUCCESSFULLY ]]
while (not Success and Attempts < MaxAttempts) do
    
    -- Try
    Success, Result = pcall(function() return Player:IsInGroup(12326302); end);
    
    if (not Success) then Attempts += 1; task.wait(1); end; -- Wait 1s if it failed
    
end;

if (Success) then
    
    print(`Success, Player is in group?: {Result}.`);
    
else
    
    warn(`Something failed. Error: {Result}`);
    
end;

This should work good?

#

Idk it shouldn't take that much, also please is really hard to read that code

#

at least for me if for you its better keep it like that

regal coral
#

yeah your formatting is better, mine was just supposed to be a quick little thing. im running tests trying to see network delay cause attempts to raise above 1, but the best i could get was a 3 second delay between 'uh' and the first print, which printed 1 true before the code continues

#

so it seems like it achieves the same thing, which makes sense because yours is just better formatted but same thing basically

tardy basin
#

seems really weird may be the internet tho or some type of problem in the method

regal coral
#

i think the problem is that its yielding until roblox returns the isingroup result

tardy basin
#

the internet may cause it to yield waiting for a response Ig

regal coral
#

damn

tardy basin
#

basically

regal coral
#

i dont see anything about yielding there

regal coral
#

im trying to use getgroupsasync as a sort of ugly workaround that wont yield, havent been able to get it to require more than 1 attempt though so who knows if it works better.

local MaxAttempts = 10;
local Attempts = 0;
local Success, Result;

while (not Success and Attempts < MaxAttempts) do
    --Success, Result = pcall(function() return player:IsInGroup(12326302); end);
    Success, Result = pcall(function()
        local groups = game:GetService("GroupService"):GetGroupsAsync(player.UserId)
        for a,grp in groups do
            if grp.Id == 12326302 then
                return true;
            end
        end
        return false
    end);
    if (not Success) then print(`failed attempt number: {Attempts}.`) Attempts += 1; task.wait(1); end; -- Wait 1s if it failed
end;

print(`Required {Attempts+1} attempt(s) to check group status.`)
if not (Success) then
    gui.LoadText.Text = "Couldn't check group status"
    task.wait(1)
end;
regal coral
#

yeah i dont think its behaving any better, its like its not that the call fails it just takes really long for the call