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:

local functions = {}
local admins = {}

functions.AddAdmin=function(plr)
    table.insert(admins,plr.lower())
end

function functions:Init(variable)
    table.insert(admins,variable)
    print(variable)
end

functions.IsAdmin=function(plr)
    for i,v in pairs(admins) do
        if v==plr.Name.lower() then
            return true
        else
            return false
        end
    end
end

return functions

Brick script:

local admins = {"StarMarine614Classic"}

touched=function(char)
    local player = game.Players:GetPlayerFromCharacter(char)
    local adminmodule = require(game:GetService("ReplicatedStorage"):WaitForChild("admin")):Init(admins)
    local isadmin = adminmodule.IsAdmin(player.Name)
    if (isadmin==true) then
        script.Parent.CanCollide = false
    end
end

script.Parent.Touched:connect(function(character)
    local player = game.Players:GetPlayerFromCharacter(character)
    local adminmodule = require(game:GetService("ReplicatedStorage"):WaitForChild("admin")):Init(admins)
    local isadmin = adminmodule.IsAdmin(player.Name)
    if (isadmin==true) then
        script.Parent.CanCollide = false
    end
end)
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

local admins = {"starmarine614classic"}

script.Parent.Touched:connect(function(character)
    local player = game.Players:GetPlayerFromCharacter(character)
    local adminmodule = require(game.ReplicatedStorage.admin):Init(admins)
    local isadmin = adminmodule.IsAdmin(player.Name)
    if (isadmin==true) then
        script.Parent.CanCollide = false
    end
end)

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:

--Lets say the script name is SETTINGS

local Settings = {
    Enabled = true 

    ,Text = 'test'
    }

return Settings -- returns Settings so the script that requires it can get information from it

In the Local Script:

local S = require(script.Parent.SETTINGS) -- assuming the local script and module script have the same parent

print(S.Text) -- prints 'test'

Answer this question