Hi
I’m trying to send a table from the server to the client. I used a remote function for that but there’ s a little problem, it sends half of the table.
server script:
local function giveWorldTable()
return worldTable
end
print(giveWorldTable())
Events.getWorldTable.OnServerInvoke = giveWorldTable
So, there is no difference (context is exceptional) between let’s say table number 8 and table number -5? Otherwise I don’t see a reason why it won’t be sent.
No different in the type, the actual model and the number changes. The number is either 0, 90, 180 or -90 and the model is a random model picked from a folder in replicated storage. It just for some reason doesn’t want to send the negatives and the 0.
Does each table contain a reference to any object? That’s because unreplicated objects references will not be sent from the server to the client (the inverse is also true).
Does each and each model that is being sent from the server to the client also exist on the client prior to the time that you invoke the RemoteFunction? If not, that may be the source of the issue, for the reason I stated in the last reply.
I don’t know, No? It’s the module script duplicating models and getting the number then putting them in a table and returning that table. Server script just calls it and then on it being invoked it sends that table to the client. But if that was the case then it wouldn’t pass anything but it does all the positive numbers.
Then you can try the following thing:
Instead of passing a reference, just pass a random string.
See if it returns all of the tables, if it does, you can conclude from that that the references you were sending from the server to the client do not exist in the client prior to invoking. Otherwise, it is another issue.
I made it so instead of the model it puts the name of the model in the table but same thing happens. Also tried moving the table generation part in the server script instead of in the module but sill only positive numbers are returned.
Because your sending an array table, remotes only like indices 1->#tbl, if you want to support negative indices then its better to use strings instead “-1” “1” etc.
So see how I use this function to generate the worldTable:
function chunkSystem:generateWorld(quadrantSize)
local worldTable = {}
local total = ((quadrantSize * 2) + 1) * ((quadrantSize * 2) + 1)
local allIndex = 0
local index = 0
for x = -quadrantSize, quadrantSize do
-- create new row --
worldTable[x] = {}
for z = -quadrantSize, quadrantSize do
-- assign chunk and chunk orientation --
local biome = getBiome(math.noise(SEED, x/chunkSystem.biomeSmoothness, z/chunkSystem.biomeSmoothness) / 1.1 + 0.5)
worldTable[x][z] = {getRandomChunk(biome), getRandomChunkAngle()}
allIndex += 1
index += 1
if index > 10000 then
index = 0
print("Generated: " .. tostring(math.floor(allIndex/total * 100)) .. "%")
wait()
end
end
end
print("GENERATED")
return worldTable
end
Would I just use worldTable[tostring(x)][tostring(z)]?
yes that is correct, simiarly remotes also dont like array tables with nil spots in them
{1,2,3,nil,4,5,6} with the string method it essentially turns into a dictionary
worldTable[x] = {}
make sure this line also has a tostring()
you would need to loop through it and use the tonumber() while also transfering it to another table, other then that not really, and isn’t something I recommand cause it would be an expensive operation to perform