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 share a table between a local script and a server script?

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.

4 comments

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

0

I did that, but I don't really like that method very much. It's too messy

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")

0

I specified a purpose

1 answer

✓ Accepted answer

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

1 comment

0

This answer is good enough. Thanks!

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