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

How to pull a table out of a module script?

I'm attempting to pull a table out of a module scripts (I've never touched module scripts before so not even sure if this is possible the way I'm hoping). It's an ignore list that I run very very often in my scripts so I figured it would be a good test to learn these things:

local module = {}
	function ignoreUpdate()
		local ignoreList = {workspace.Projectiles}
			
		local players = game:GetService("Players"):GetChildren()
		for i = 1, #players do
			ignoreList[#ignoreList + 1] = players[i].Character
		end
		return ignoreList
	end
return module

I essentially need this ignoreList updated every time right before I cast a new ray. Only problem is I'm clueless on how to actually pull the ignoreList out of it. I've tried quite a few different ways but to no success. This is my most recent attempt at it which is roughly off of what I could find on youtube since the wiki has been almost less than useless.

local module = require(game:GetService("ServerScriptService").UpdatingIgnore)

local ignoreList = module.ignoreUpdate()

However, when printing ignoreList it has always been nil. So I'm officially back to square one on this one.

3 comments

1

In your module's current state, it is impossible to. the ignorelist is neither accessibly directly via the module script(its not a part of the module), or via the  ignoreUpdates function(the function doesnt return the table)

0

So in other words move the function between the module brackets and have it return the ignoreList?

0

Also, I did actually have it return the ignoreList under the ignoreUpdates. Sorry. I had to rewrite it. Let me update the question with that part.

1 answer

✓ Accepted answer

This is all wrong

local module = {}
function module.ignoreUpdate()
	local ignoreList = {workspace.Projectiles}
	local players = game:GetService("Players"):GetChildren()
	for i = 1, #players do
		ignoreList[#ignoreList + 1] = players[i].Character
	end
	return IgnoreList
end
return module

You have to return a value in the module function.

local module = require(game:GetService("ServerScriptService").UpdatingIgnore)

local ignoreList = module.ignoreUpdate()

2 comments

0

Huh. Strange. I know I've tried this before and I kept getting "Attempt to index upvalue module (a nil value)". Maybe I was making a spelling error at the time and didn't catch it. Thank you though.

0

mhm Ofc

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