Module script:
01 | local functions = { } |
02 | local admins = { } |
03 |
04 | functions.AddAdmin = function (plr) |
05 | table.insert(admins,plr.lower()) |
06 | end |
07 |
08 | function functions:Init(variable) |
09 | table.insert(admins,variable) |
10 | print (variable) |
11 | end |
12 |
13 | functions.IsAdmin = function (plr) |
14 | for i,v in pairs (admins) do |
15 | if v = = plr.Name.lower() then |
Brick script:
01 | local admins = { "StarMarine614Classic" } |
02 |
03 | touched = function (char) |
04 | local player = game.Players:GetPlayerFromCharacter(char) |
05 | local adminmodule = require(game:GetService( "ReplicatedStorage" ):WaitForChild( "admin" )):Init(admins) |
06 | local isadmin = adminmodule.IsAdmin(player.Name) |
07 | if (isadmin = = true ) then |
08 | script.Parent.CanCollide = false |
09 | end |
10 | end |
11 |
12 | script.Parent.Touched:connect( function (character) |
13 | local player = game.Players:GetPlayerFromCharacter(character) |
14 | local adminmodule = require(game:GetService( "ReplicatedStorage" ):WaitForChild( "admin" )):Init(admins) |
15 | local isadmin = adminmodule.IsAdmin(player.Name) |
16 | if (isadmin = = true ) then |
17 | script.Parent.CanCollide = false |
18 | end |
19 | end ) |
I did this to the local script and turned it into a script
01 | local admins = { "starmarine614classic" } |
02 |
03 | script.Parent.Touched:connect( function (character) |
04 | local player = game.Players:GetPlayerFromCharacter(character) |
05 | local adminmodule = require(game.ReplicatedStorage.admin):Init(admins) |
06 | local isadmin = adminmodule.IsAdmin(player.Name) |
07 | if (isadmin = = true ) then |
08 | script.Parent.CanCollide = false |
09 | end |
10 | end ) |
Gives this error: 17:52:58.591 - Workspace.Part.Script:6: attempt to index local 'adminmodule' (a nil value)
You can see at the bottom of the module script it says, "return functions". There is nothing between the functions arrays-(local functions ={}) so when you require the module script, you will receive nil.
I never tried to call functions from module scripts, but here is a example of how I use it:
1 | --Lets say the script name is SETTINGS |
2 |
3 | local Settings = { |
4 | Enabled = true |
5 |
6 | ,Text = 'test' |
7 | } |
8 |
9 | return Settings -- returns Settings so the script that requires it can get information from it |
In the Local Script:
1 | local S = require(script.Parent.SETTINGS) -- assuming the local script and module script have the same parent |
2 |
3 | print (S.Text) -- prints 'test' |