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

Module script and localscript won't work, can someone help me?

Asked by 6 years ago

Module script:

01local functions = {}
02local admins = {}
03 
04functions.AddAdmin=function(plr)
05    table.insert(admins,plr.lower())
06end
07 
08function functions:Init(variable)
09    table.insert(admins,variable)
10    print(variable)
11end
12 
13functions.IsAdmin=function(plr)
14    for i,v in pairs(admins) do
15        if v==plr.Name.lower() then
View all 23 lines...

Brick script:

01local admins = {"StarMarine614Classic"}
02 
03touched=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
10end
11 
12script.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
19end)
0
P.S. don't worry about the first function and I think this should have been in a script StarMarine614Classic 14 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

I did this to the local script and turned it into a script

01local admins = {"starmarine614classic"}
02 
03script.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
10end)

Gives this error: 17:52:58.591 - Workspace.Part.Script:6: attempt to index local 'adminmodule' (a nil value)

Ad
Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

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 
3local Settings = {
4    Enabled = true
5 
6    ,Text = 'test'
7    }
8 
9return Settings -- returns Settings so the script that requires it can get information from it

In the Local Script:

1local S = require(script.Parent.SETTINGS) -- assuming the local script and module script have the same parent
2 
3print(S.Text) -- prints 'test'

Answer this question