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

How would I create a table that can be accessed by both the server and the client?

I'm trying to create a table for each player that enters that can be accessed by both the server and the client. I have already looked into ModuleScripts, and I am almost certain that they wouldn't work. So how would I do this?

2 comments

0

You could use a RemoteFunction, return a table when the LocalScript requests it...

0

No need. Module scripts work as per my solution expands upon

1 answer

✓ Accepted answer

Modules

When you create a new module script, you should notice the default code placed is along the lines of:

local module = {}

return module

This means that module scripts by DEFAULT return arrays if you keep it as it is. Module scripts WILL work for this. You may commonly see people using module scripts for functions, but be aware that many people actually store the functions IN THE ARRAY.

WARNING


Only ReplicatedStorage and ReplicatedFirst will replicate any edits made to the array to both the server and the Client.


So lets try making a module script that returns an array with specific values:

ReplicatedStorage

local module = {"Digital","Veer"}

return module


Now lets access it from a local-script and server-script:

Local [Starterpack/StarterGui]

local mod = require(game.ReplicatedStorage["ModuleScript"])
print(mod[1])

Server [Workspace]

local mod = require(game.ReplicatedStorage["ModuleScript"])
print(mod[2])

Output

Your output should be:

DigitalVeer

2 comments

0

How do you make dose rlly big lettarz? O:

0

@Goulstem #Hashtag

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