Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

1 comment

0

P.S. don't worry about the first function and I think this should have been in a script

2 answers

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)

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'

This discussion is preserved as it was. New answers, comments, and votes are closed.