Help with returning arrays

I’m writing a script (function) that will return an array of whether or not a player is in a specific group in a larger list of groups. Let me explain, I get it’s confusing.

We will have our groups. In my case, there’s about 15

GroupA = 1
GroupB = 2
GroupC = 3

What I want is a function that will do this

local function = groupcheck(player)
    local grouplist = {}
    if player:IsInGroup(GroupA) then
        table.insert(grouplist, GroupA = true)
    else
        table.insert(grouplist, GroupA = false)
    end
    -- And repeat for all the groups
end

Then back at the main code

groupcheck(player)
return grouplist
-- Then here be able to check which groups the player is in and which ones they aren't.
-- Like, in grouplist, if player is in group A and B BUT not in group C. Or Is in C but not A and B

This is all concept, all help is greatly appreciated

Solved by a friend of mine. Just make the table public and have it over-written each time

1 Like

This is how you should do it.

local groups = { --A table containing the ids of the groups
GroupA = 1,
GroupB = 2,
GroupC = 3,
}

local function groupcheck(player)
local grouplist = {}
for group, id in pairs(groups) do --Group is the name of the variable, and id is the value.
grouplist[group] = player:IsInGroup(id) --You can later say "grouplist.GroupA" and get the value.
end
return grouplist
end

--In another script
local grouplist = groupcheck(player)
1 Like

I don’t think those are meant to be strings

2 Likes