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

Pass a table from a normal Script to a local script - Is it possible?

Hi! I have a Script in wich i have a table

mytable  = {
	
	[1] = "Element1",
	[2] = "Element2",
	[3] = "Element3"
	
	}

I want to pass it to my LocalScript in wich i have

print(mytable[1])

Is there any way to do it? Thanks in advance!

2 comments

0

you can use remote events

0

Module Script, it's more effective.

1 answer

✓ Accepted answer

Yes, in fact with FilteringEnabled turned on (Which is very important), you kinda have to have exclusive communication between the client and the server and vice versa.

I present to you: RemoteEvents

RemoteEvents can have its event called from the server or client to have its parameters sent to the other end, you usually place RemoteEvents (and RemoteFunctions) in ReplicatedStorage (its like ServerStorage, but the clients get to peek in aswell)

Client side:

-- this is a localscript
local Event = game.ReplicatedStorage.SendBeans -- the RemoteEvent in question
local Beans = 0 -- how many beans we currently have

Event.OnClientEvent(function(BeansToGive)
	Beans = Beans + BeansToGive
end)

Server side: it should be noted that you have to specify which client you are communicating with as the first parameter

-- this is a server script
local Event = game.ReplicatedStorage.SendBeans -- the RemoteEvent, yet again
local Player = game.Players.fanofpixels
local BeansStorage = 10

function GiveBeans()
	Event:FireClient(Player, BeansStorage)
	BeansStorage = 0
end

GiveBeans()

-- if you are trying to fire the event for ALL clients, then try this method instead:
Event:FireAllClients(BeansStorage)

More information can be found here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

2 comments

0

Thank you, I'll try it and I'll let u know

0

It works, thank you.

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