(SOLVED) How to send a folder full of information to the server?

Nothing, other than the fact i already spent time making it this way :person_shrugging:

2 Likes

Yeah I think what @Content_Corrupted019 said is a great implmentation, how are you setting up the client folder right now, it would probably easy to just set it up for every player on the server

1 Like

The descendants of the Demands folder come and go, I just want to know how to send the information of the folder.

1 Like

if the folder and its descendants are created on the client then I would either A) set everything up to be table based over instance based then you can easily send the dictionary to the server, or B) make a function to convert the instances to a dictionary then send that to the server. I would heavily suggest either making it server sided to begin with or going for the dictionary version.

Of course if this info is important then I would 100% make it all server-sided, otherwise the client can modify it however they want and there’s no way to verify that information.

3 Likes

How would i turn it all into a dictionary and still keep the ordered structure of it? Also, its important to note that in the dictionary it must still retain its values, since most of the descendants are object/number values.

Also the player can modify the folder through the guis I made, or they can modify it through hacks. Either way, when it sends to the server its going to be inspected and checked to make sure theres nothing fishy.

1 Like

you could make it look something like this (this is just one example)

local t = {
	["Demands"] = {
		["AnnexProvincesMAMLUKS"] = {
			["Provinces"] = {
				["Mentese"] = 5
			}
		},
		
		["Break Alliance"] = {
			["Country"] = 1,
			["NegotiatingFor"] = 2,
			--...
		},
	}
}

and you could achieve creating this dynamically with a recursive function

2 Likes

This cant work because demands come and go, all the names, values, and layers of descendants arent permenent/constant.

1 Like

then you could do what I said in my first reply and convert it to a table each time you send it (though not the best for performance)

In my opinion it’d be better to have a cached version of the table stored on the server that you modify with remotes checking each change then instead of verifying every entry each time they update something.

function for this:

2 Likes


The code works beautifully at what its supposed to do, but now I’m just wonder how would I now go about adding the descendants of the children and their descendants etc?

1 Like

did you pass the Demands folder to the function? It should return a dictionary with everything in it

2 Likes

It only gets the direct children of the Demands Folder :confused:

local function folderToDictionary(folder)
    local dictionary = {}

    for _, object in ipairs(folder:GetChildren()) do
        if object:IsA("Folder") then
            dictionary[object.Name] = folderToDictionary(object)
        elseif object:IsA("ValueBase") or object.ClassName:match("Value") then
            dictionary[object.Name] = object.Value
        end
    end

    return dictionary
end

1 Like

would changing folder:GetChildren() to folder:GetDescendants() fix it?

2 Likes

Defiantly not, that would turn it into one big clump of information, it wouldn’t keep the structure.

1 Like

Perhaps what you’re really looking for is a way to convert the values to a table? Sending entire instances over isn’t helpful because since they aren’t replicated to the server, you will only have copies(if you decide to serialize for example), and changing the values there won’t also change them on the client(unless you use remotes and change the client-sided values).

Here’s a function that can convert the format of instances you provided to a table:

type valTypes = (boolean | BrickColor | CFrame | Color3 | number 
	| Instance | Ray | string | Vector3)

local function folderToTable(folder: Instance): {[string]: valTypes}
	local t = {}
	for i, v in pairs(folder:GetChildren()) do
		if v:IsA("Folder") then
			t[v.Name] = folderToTable(v)
		elseif v:IsA("ValueBase") then
			t[v.Name] = v.Value
		end
	end
	return t 
end

You can run it on the client and send the table to the server instead.

Keep in mind:

  1. The function won’t function properly if 2 instances have the same name under the same folder.
  2. If one of the values is nil, the key associated with it won’t exist within the table.
  3. For this to work you will have to convert Break Alliance, GoldDemand and War Reperations to folders.

Here’s an example of accessing the data of the table:

--For instances that don't have spaces:
local goldSummaryDirectory = data.GoldDemand.SummaryDirectory
--for instances with spaces:
local country = data["Break Alliance"].Country
1 Like

Thanks for the response but theres gonna be a lot of instances with the same name. Also im so close to actually making this work, im just confused on one question

local function folderToDictionary(folder)
    local dictionary = {}

    for _, object in ipairs(folder:GetChildren()) do
        if object:IsA("Folder") then
            dictionary[object.Name] = folderToDictionary(object)
        elseif object:IsA("ValueBase") or object.ClassName:match("Value") then
            dictionary[object.Name] = folderToDictionary(object) ----- QUESTION HERE 
         --this recursive adds objects' children but how do i add object.Value along with it???
        end
    end

    return dictionary
end

image

as you can see they all have their children, but are missing their values

is there no way to give “1” a name? going Something.NumberValue.1 will error out

For the elseif do v.Value instead, and as I mentioned change all values that act as folders to folders. If you store any data in them(for example if GoldDemand except of children also has a value), make it a new value under said folder.

For example GoldDemand becomes a folder but now has 2 values, SummaryDirectory and Gold which was the original GoldDemand value.

Is there also a way to make it so it dosnt say the objects name twice. As you can see it says “War reoperations” twice, how could i make it so the children of the 2nd war reparations are just placed in the first one?

Solved it, i just turned the Value into an actual instance and used the regular code :+1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.