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

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

Asked by 4 years ago

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!

0
you can use remote events abnotaddable 920 — 4y
0
Module Script, it's more effective. Foxy_Developer 111 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

0
Thank you, I'll try it and I'll let u know Stephirio 7 — 4y
0
It works, thank you. Stephirio 7 — 4y
Ad

Answer this question