Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
parkderp1 105
9 years ago

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?

0
You could use a RemoteFunction, return a table when the LocalScript requests it... M39a9am3R 3210 — 9y
0
No need. Module scripts work as per my solution expands upon DigitalVeer 1473 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

Modules

When you create a new modulescript, 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

0
How do you make dose rlly big lettarz? O: Goulstem 8144 — 9y
0
@Goulstem #Hashtag Redbullusa 1580 — 9y
Ad

Answer this question