I have code, but it doesn't work, heres my code:
Client:
local Example = {"Test"} script.Parent.Activated:Connect(function() game.ReplicatedStorage.Submit:FireServer(Example) end)
Server:
game.ReplicatedStorage.Submit.OnServerEvent:Connect(function(player, request, data) if request == "Example" then for i, v in pairs (data) do print(v) end end end)
The reason this doesent work is because of line 1 in the server script. When you do :Connect(function(player, request, data), player equals the player, request equals the table, and data is nil. The first argument is the player who fired the event, the second is the first argument, and in your case, the third is nil because there is no second arg fired. To fix this, replace line 5 of the client with this:
game.ReplicatedStorage.Submit:FireServer("Example",Example)
This is because the table is one value, and the variable name isnt fired by default.
Since there is only 1 value being processed, you dont really need to put it through a table, so
local Example = "Test"
is fine.
However, when you do need to put a table through it, there are multiple ways of doing it. First, your method, the way you would receive would be:
game.ReplicatedStorage.Submit.OnServerEvent:Connect(function(player, request, data) if request[1] == "Example" then for i, v in pairs (data) do print(v) end end end)
This searches through the table and finds the first value.
What I like to do is this:
local Example = {} Example.CMD = "Example" script.Parent.Activated:Connect(function() game.ReplicatedStorage.Submit:FireServer(Example) end) -- Local -- Server game.ReplicatedStorage.Submit.OnServerEvent:Connect(function(player, request, data) if request.CMD == "Example" then for i, v in pairs (data) do print(v) end end end)
With the way I use, I can easily get table values without having to search through the number order, and easily access them.
Hope this helps!
What i do is this:
Client:
local re = game.ReplicatedStorage.RE local tab = {name = "Tim", age = 18} re:FireServer(tab)
Server:
local re = game.ReplicatedStorage.RE re.OnServerEvent:connect(function(player,tab) local args = unpack({tab}) print("Name :"..args.name) print("Age :"..args.age) end)
hope this helps :)