#Script not recognizing second element within an array

1 messages · Page 1 of 1 (latest)

fallow storm
#

So, I have a script that checks groups and in my nested code, one of the if statements checks if theres Groupperms[2], if there is then it goes into logic that checks if youre in both groups. The script doesnt recognize the second string and just goes into the single group logic.

#

function CheckPermissions(Player, PermissionObject)
local RequireTeam = true
local GPLocked = false
local Gamepasses = PermissionObject.Gamepass
local TeamPerms = PermissionObject.TeamPerms
local GroupPerms = PermissionObject.GroupPerms

if PermissionObject.RequireTeam == true then
    RequireTeam = true
end
if PermissionObject.IsGamepassLocked == true then
    GPLocked = true
end
if GPLocked == true then
    local OwnsGamepass = false
    if Gamepasses[1] then
        for i = 1,#Gamepasses do
            if MarketplaceService:UserOwnsGamePassAsync(Player.UserId,Gamepasses[i]) then
                OwnsGamepass = true
            end    
        end
    end
    --
    if OwnsGamepass == true then
        return true
    else
        return false
    end
else -- If GamepassLocked is false
    local Authorised = false
    --
    local function CheckTeams()
        if TeamPerms[1] then
            for x = 1,#TeamPerms do
                if Player.Team.Name == TeamPerms[x] then
                    Authorised = true
                    return true
                end
            end
        end
    end
    --
    if GroupPerms[1] then
        
        if RequireTeam == true then
            for i = 1,#GroupPerms do
                local Split = string.split(GroupPerms[i],":")
                if GroupPerms[2] then
                    local Split2 = string.split(GroupPerms[2],":")                        
                    if Player:GetRankInGroup(Split[1]) >= tonumber(Split[2]) and Player:GetRankInGroup(Split2[1]) >= tonumber(Split2[2]) then
                        if CheckTeams() == true then
                            Authorised = true
                            print("fart2")
                            return true
                        else
                            print("fart3")
                            return false
                        end
                    else
                        print("fart4")
                        return false
                    end
                else                    
                    for i = 1,#GroupPerms do                        
                        local Split = string.split(GroupPerms[i],":")                                                    
                        if Player:GetRankInGroup(Split[1]) >= tonumber(Split[2]) then
                            Authorised = true        
                            print("fart")
                            return true                                
                        end                        
                    end                            
                end    
            end
        end
        
    else
        for i = 1,#GroupPerms do
            local Split = string.split(GroupPerms[i],":")
            if Player:GetRankInGroup(Split[1]) >= tonumber(Split[2]) then
                Authorised = true
                return true
            end
        end
        
    end    
    
end

end

#

(secondary script with arrays that it refers to)

local module = {

["RequireTeam"] = true, -- true: will need to be in one of the listed teams as well as being in the group/owning the gamepass
["IsGamepassLocked"] = false, -- true: ONLY the gamepass matters, all other perm types will be ignored
["Gamepass"] = {""}, -- Copy the format "1231312","123123123" to add more
["TeamPerms"] = {""}, -- Leave as {""} if you want no teams
["GroupPerms"] = {"35936720:1", "32036040:1"}, -- Leave as {""} if you want no groups

}

return module

#

(the prints were to figure out what was actually firing lol)

crude light
#

problem is likely that youre checking for GroupPerms[2] insie a group that already iterates for GroupPerms so the logic breaks when GroupPerms[2] is nil even if youre on i = 2 ...

fallow storm
#

How do I refer to the second string then?

crude light
#

the new script surpasses the character count so ill try to explain, you should use ipairs() for clean iteration, then you should also Wrap team check in a helper function and make it respect RequireTeam. ( also Use clearer structure for readability and logic separation) if this is hard to understand i can try edit your script and dm it to you since its too long to post here.