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

Insert a table from different script?

can you insert a table from different script? for example = script 1 : list = {} script 2 : insert integer data inside "list" from script 1

1 comment

0

You might be able to do that with a module script.

1 answer

You can use a ModuleScript that can be used to hold data.

ModuleScript is basically a storage script, it can be used as a ServerScript, if you use it correctly, but the main use is to holster functions that are used multiple times in multiple scripts, including tables, variables, and the functions.

I also recommend storing ModuleScripts in ReplicatedStorage so LocalScripts and ServerScripts can access the module, as ServerScriptService cannot be accessed from LocalScripts.

ModuleScript

local tableModule = {"A","B","C"}

return tableModule

Now, if you use a LocalScript or ServerScript and call that, like this.

local mod = require(game:GetService("ReplicatedStorage").ModuleScript)

print(mod[2])

This will return B since we are indexing the table by 2

You can also do the same thing with functions.

local tableModule = {"A","B","C"}

tableModule:GetLetter(num)
	return tableModule[num]
end

return tableModule

In a LocalScript or ServerScript

local mod = require(game:GetService("ReplicatedStorage").ModuleScript)

print(mod:GetLetter(1))

This will print A, since we are indexing the table with 1


If you want to go somewhat in-depth about ModuleScripts, look at my post below. It also explains LocalScripts, ServerScripts, ModuleScripts, and there's a post on there about RemoteEvents.

Script Post w/ RemoteEvents

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