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)
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!
5 comments
You´re only firing one argument, so data is (theoretically) nil.
What do I need to put instead then?
Fire a second table to the server and data won´t be nil.
Can you show me an example in the answer area?
ClientSided Fix:
Add Example to line 5 as first argument, or whatever it's called.
game.ReplicatedStorage.Submit:FireServer("Example", Example)ServerSided Fix (if you didn't do the ClientSided Fix):
Remove
if request == "Example" thenand replacedatawithrequestfor i, v in pairs (request) do print(v) end