Loosing contents of table when sending from Server to Client

I’m trying to send over the contents of a Folder inside of ServerStorage to the Client to be interpreted and displayed in a GUI.

Server:

friskEvent.OnServerEvent:Connect(function(plr, tool : Tool)
	local targetPlr : Player = services.players:FindFirstChild(tool:GetAttribute("detainee"))
	
	local items = detainedPlrItemsFolder:FindFirstChild(targetPlr.Name):GetChildren()
	print(items)
	friskEvent:FireClient(plr, items, "")
end)

detainedPlrItemsFolder is a folder inside of ServerStorage, which contains sub-folders that contain the items of players. When printing out the items varaible from the server, the contents are correct:
image

Client:

friskEvent.OnClientEvent:Connect(function(items)
	print(items)
end)

In the client, all I am doing is printing out the table sent by the server. However, instead of the correct table; it only prints out a blank table.

I’ve tried moving the contents of the detainedPlrsItemFolder sub-folder’s children into the items variable then sending it, the same happens.

friskEvent.OnServerEvent:Connect(function(plr, tool : Tool)
	local targetPlr : Player = services.players:FindFirstChild(tool:GetAttribute("detainee"))
	
	local items = {}
	table.move(detainedPlrItemsFolder:FindFirstChild(targetPlr.Name):GetChildren(), 1, #detainedPlrItemsFolder:FindFirstChild(targetPlr.Name):GetChildren(), 1, items)
	print(items)
	friskEvent:FireClient(plr, items)
end)
1 Like

This is because the instance does not exist on the client due to it being in ServerStorage.

1 Like

This is why I am storing the contents of the folder in a variable, then passing it over.

i believe i’ve had the same problem for some reason, did you make it into something like

Table = {
["Tool"] = Tool
}

and not:

Table = {Tool}
1 Like

I’m not writing out the table by hand, I’m using :GetChildren() on a folder.

1 Like

That’s not how it works, the instance is still in ServerStorage, you cannot replicate items in places like ServerScriptService or ServerStorage unless you change their parent to something that is being replicated.

Edit: This can be fixed by first cloning everything and then sending them over.

1 Like

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