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

Accessing tables inside a ModuleScript?

Asked by
Bman8765 270 Moderation Voter
9 years ago

I am currently working on an admin script but I am having some issues with the settings area mainly because I have never worked with ModuleScripts before but I feel like it is the best route to take. So my question is, how would I access the contents like admins etc. in this module script from another script? I am making a function that checks to see if the player is an admin (found below the module script) and I don't know how I would check the admin table inside the ranks dictionary.

Any advice would be great (wiki links, etc.). Thanks!

ModuleScript

--[[
These are the settings for Bman's Admin, if you have any questions or issues please contact
me (Bman8765) by sending me a message and I'll try to help!
--]]

return {
    ----------------[[ ADMINS ]]-----------------
    Ranks = {
        ["Admin"] = {"Bman8765"}; -- Can use everything
        ["Banned"] = {"Noob", "Butt", "Idiot"}; -- Locked out of the server
    }
    ---------------------------------------------

    ----------------[[ SETTINGS ]]---------------

    ---------------------------------------------
}

The Function for checking if an admin

function adminCheck(name)
    for _, Name in pairs (IDK HOW TO ACCESS THE TABLE HERE) do
        if (Name == name) then
            return true
        end
    end
    return false
end
0
Yea mine runs off a module script, I feel your confusion.. MessorAdmin 598 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I'm guessing that your module script is returning a function (which is generally what you want to do to load your module). When you want to access your table, you put it as an argument for the function you're returning.

In your module script:

return function(tables)
    --do module script here
    return adminsettings -- Return the settings for our admin.
end

and in your main loader script

func = require(module) -- This will load our module script, into a function that we can run.
settings = func(table1, table2, table3) -- I'm not sure if this is the correct syntax, but you do something like this.
0
Worked, thanks for the help Bman8765 270 — 9y
Ad

Answer this question