How would i split and merge a table?

In my game i need to send a table containing up to 260k characters in a remote event, and for that i will need to split it in several small tables. And then merge them on the other side. I have tried several ways but none worked. And now im asking here, so, how would i split and merge a table?

No offense but have you took an attempt at trying to do that at all?

If the answer is no then I can provide you some very useful links that will help you straight from the Roblox Developer API Reference:

String Manipulation
String Patterns

Go to the above links and try to do this for yourself and if you run into any problems in the process then show us the code that you have problems with we will gladly help you fix those problems in your code, this category is for helping people fix problems in their code. :slightly_smiling_face:

1 Like

Please read the OP :slight_smile: OP is trying to compress a table.

Answering the OP though,
I think the issue is the implementation. @index_nil ould you explain how you ended up needing to send a table of such magnitude anyways? Remember there is a limit of 50kb.

Im needing to send the data of about 30k blocks through a remote event to load the parts for each player localy, and yes, thats why im needing to split the table up in several parts, cause of the limit

260k is so many why do you need that many?

Im making a building game, and about 40k blocks is the maximum limit, so when the player joins it must send all that info about those 40k blocks to all the clients. And instead of sending 40k events ill make it send just 1 containing all the info, but i need to split it up since there is a limit on how much you can send.

what why would u need 40k events

So you want to send info about every space you can place a block in?
Seems kind of wasteful, why not just send info about only the placed blocks?
Does the client load the blocks? Why doesn’t the server just place the blocks in workspace. That way you don’t have to send info to the client.

No, why would i do that, i said that im sending the info about all the blocks

And the reason i place them on the clients is a really long story.

To split a table into parts would be quite a challenge. To split a string into parts wouldn’t be that much of a challenge, especially since you can just fire the events multiple times with an ID number of the string part attached, which the local script can then easily reconstruct back into the full string, ready for conversion.

Roblox has built-in functionality for converting arrays to strings and vice-versa. I suggest taking a look at Service: HttpService, the relevant functionality is listed under HttpService:JSONEncode() and HttpService:JSONDecode().

Once you have a string, you can use the links provided in a post above to chop it up into pieces ready for transport.

yeah, i tried that, but i had no idea on how to split a string into more than 2 parts. I searched for like 1 hour and found no answer.

Well, if you split a string in two parts, you get two new strings, one piece that is ready for transport and one piece that likely isn’t ready for transport. Just split that second piece again.

Table splitting function
local insert = table.insert
local move = table.move

function table_split( t, max_size )
	local result = {}
	
	for i = 1, #t, max_size do
		local tn = {}
		insert(result, tn)
		move(t, i, i + max_size, 1, tn)
	end

	return result
end

EDIT: Oh, and definitely DON’T send the table JSON encoded. Look up bitbuffer to see how to send data efficiently over the network.

1 Like

there is this thing called string:split()

local twostrings = "hey guys"
twostrings = twostrings:split()
print(twostrings)

will print a table

I already tried that, but the problem is that i have no idea how many times it should split, it is completelly uneccesary so split the string 4 times if there is like only 10 characters.

Yes i know i can use tons of If’s to check that, but i wanted to ask here if there was any other way that is better.

To split a long string into viable parts I would use the following workflow. (This is just basic problem resolution, take steps that bring you closer to the result and figure out when you have achieved the desired result.)

Check the length of the input string, if it is longer than the max length, split at the max length and store the first part somewhere, then do the exact same thing for the second part. (Ideally in a loop.)
If the length of the input string is not longer than the max length, store that part and break out of the loop.

You shouldn’t need to worry about this, if statements aren’t that resource-intensive and I would see no other way as to how to go about this.