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

How would I share a table between a local script and a server script?

Asked by 10 years ago

I tried to use module scripts, but I need to access that table from other server scripts as well, so that wouldn't work.

I tried to use _G, but _G is different for local scripts and server scripts.

Basically what I want is for a server side script to create a table of items, and I want a local script and other server scripts to be able to access that table. Any suggestions?

MY PURPOSE:

I'm designing a Helicopter kit, which will be a successor to my Military Planekit V2. The Helicopter kit will have 1 script that regens the helicopter, welds it, and checks if it crashed. The weld part of the script will also weld rotors, so that they can spin, and I store those welds in a table. I want to access that table from a Hopperbin, so that when a player starts the helicopter, the localscript will access that table of welds instead of scanning the helicopter for rotor welds.

0
I'm not sure if this is the BEST answer but you could have a holder (i.e. Configuration or Model) to hold the values and then save the values as various string values inside the thing and then use :GetChildren() to access the table basically VariadicFunction 335 — 10y
0
I did that, but I don't really like that method very much. It's too messy TurboFusion 1821 — 10y
1
WHY do you want to do this? This generally isn't something that you'd want to to do, so you should specify a specific purpose (more than just "accessing a table of items") BlueTaslem 18071 — 10y
0
I specified a purpose TurboFusion 1821 — 10y

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

Ever thought about using Remote Functions? You can use them to pass functions from a server script to a local script and vice versa.

Server Script:

local remoteFunction= game.ServerStorage.RemoteFunction -- Location of RemoteFunction

function remoteFunction.OnServerInvoke()
    local array = {'Hello World'} -- Do what you wish to generate this
    return array
end

Local Script:

local remoteFunction= game.ServerStorage.RemoteFunction -- Location of RemoteFunction

local array = remoteFunction:InvokeServer()
print(array[1]) -- Will print 'Hello World' in this case

Additional documentation

0
This answer is good enough. Thanks! TurboFusion 1821 — 10y
Ad

Answer this question