Cant use a table from a local script in a Server Script

so i have a table in a local script with selection boxes and i have to transfer to a server script so i can use it in a remote event (local script → remote:FireServer(table) ) but when i do that it clears the table and says that the table has 0 children in it

if you dont understand what im trying to say then im gonna try to explain it a little bit better

Can I see your local script, I am pretty sure that you can send tables using remote events. There might be an error in the code.

okay here it is:
(selectionboxesremote is the remote im talking about)

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local RS = game:GetService("RunService")
local tablewithsboxes = {}
local tool = script.Parent
local branchInfoFunc = game.ReplicatedStorage.Remotes.Branches
local getsawinfo = game.ReplicatedStorage.Remotes.GetSawInfo
function remove(array, value)
	for i, v in ipairs(array) do
		if value == v then
			return table.remove(array, i)
		end
	end
end
local selectionboxesremote = game:GetService("ReplicatedStorage").Remotes.SelectionBoxes

RS.RenderStepped:Connect(function()
	wait()
	if tool.Parent.Name == plr.Name then
		if mouse.Target ~= nil then
			local pos = mouse.Hit.p
			local char = plr.Character
			local target = mouse.Target
			local plrx = char.HumanoidRootPart.Position.X
			local plry = char.HumanoidRootPart.Position.Y
			local plrz = char.HumanoidRootPart.Position.Z
			local objx = pos.X
			local objy = pos.Y
			local objz = pos.Z
			local calcx = plrx - objx
			local calcy = plry - objy
			local calcz = plrz - objz
			local BeamFirst = calcx^2 + calcy^2 + calcz^2
			local BeamTwo = math.sqrt(BeamFirst)
			if BeamTwo <= 15 then
				if target.Name == "Srodek" then
					if target.Parent.Anchored == false then
						local log = target.Parent
						if log.IsDead.Value == false then
							local info = branchInfoFunc:InvokeServer(log.Parent.RodzajDrzewa.Value,log)
							local sizeX = 2
							local sizeY = 0.3
							local sizeZ = 3
							local objdeski = sizeX*sizeY*sizeZ
							local pole = sizeX*sizeZ
							local lacznaobjetosc = 0
							for i,v in pairs(info.allbranches) do
								local objetoscloga = v.Size.X*v.Size.Y*v.Size.Z
								lacznaobjetosc = lacznaobjetosc + objetoscloga
							end
							local sawinfo = getsawinfo:InvokeServer(tool.Name)
							if lacznaobjetosc <= sawinfo.maxobjetosc and lacznaobjetosc >= sawinfo.minobjetosc then
								for i,v in pairs(info.allbranches) do
									if v:FindFirstChildWhichIsA("SelectionBox") == nil then
										local sbox = Instance.new("SelectionBox",v)
										sbox.Color3 = v.Srodek.Color
										sbox.Adornee = v
										sbox.LineThickness = 0.05
										table.insert(tablewithsboxes,sbox)
									end
								end
								selectionboxesremote:FireServer(tablewithsboxes)
							else
								for i,v in pairs(info.allbranches) do
									if v:FindFirstChildWhichIsA("SelectionBox") == nil then
										local sbox = Instance.new("SelectionBox",v)
										sbox.Color3 = Color3.fromRGB(208, 0, 0)
										sbox.Adornee = v
										sbox.LineThickness = 0.05
										table.insert(tablewithsboxes,sbox)
									end
								end
								selectionboxesremote:FireServer(tablewithsboxes)
							end
						end
					end
				elseif target.Name == "Drewno" then
					if target.Anchored == false then
						local log = target
						if log.IsDead.Value == false then
							local info = branchInfoFunc:InvokeServer(log.Parent.RodzajDrzewa.Value,log)
							local sizeX = 2
							local sizeY = 0.3
							local sizeZ = 3
							local objdeski = sizeX*sizeY*sizeZ
							local pole = sizeX*sizeZ
							local lacznaobjetosc = 0
							for i,v in pairs(info.allbranches) do
								local objetoscloga = v.Size.X*v.Size.Y*v.Size.Z
								lacznaobjetosc = lacznaobjetosc + objetoscloga
							end
							local sawinfo = getsawinfo:InvokeServer(tool.Name)
							if lacznaobjetosc <= sawinfo.maxobjetosc and lacznaobjetosc >= sawinfo.minobjetosc then
								for i,v in pairs(info.allbranches) do
									if v:FindFirstChildWhichIsA("SelectionBox") == nil then
										local sbox = Instance.new("SelectionBox",v)
										sbox.Color3 = v.Srodek.Color
										sbox.Adornee = v
										sbox.LineThickness = 0.05
										table.insert(tablewithsboxes,sbox)
									end
								end
								selectionboxesremote:FireServer(tablewithsboxes)
							else
								for i,v in pairs(info.allbranches) do
									if v:FindFirstChildWhichIsA("SelectionBox") == nil then
										local sbox = Instance.new("SelectionBox",v)
										sbox.Color3 = Color3.fromRGB(208, 0, 0)
										sbox.Adornee = v
										sbox.LineThickness = 0.05
										table.insert(tablewithsboxes,sbox)
									end
								end
								print(#tablewithsboxes)
								selectionboxesremote:FireServer(tablewithsboxes)
							end
						end
					end
				else
					for i,v in pairs(tablewithsboxes) do
						remove(tablewithsboxes,v)
						v:Destroy()
					end
				end
			else
				for i,v in pairs(tablewithsboxes) do
					remove(tablewithsboxes,v)
					v:Destroy()
				end
			end
		else
			for i,v in pairs(tablewithsboxes) do
				remove(tablewithsboxes,v)
				v:Destroy()
			end
		end
	else
		for i,v in pairs(tablewithsboxes) do
			remove(tablewithsboxes,v)
			v:Destroy()
		end
	end
end)

i cannot change the script to lua

Could you format your code using the following without the --. It is three of these ` then the code.
It is the key just above tab, and just below esc.

--```
--code
--```

there we go finally working thanks

1 Like

If before firing the server, you did the following, does it print anything?

for i,v pairs(tablewithsboxes) do
      print(i, v)
end

i did print(#tablewithsboxes) and i got 4 so it means there were selection boxes in it, but when i did that in the remote it printed out 0

Strange, can I see the server script?

local remote = game.ReplicatedStorage.Remotes.SelectionBoxes

remote.OnServerEvent:Connect(function(plr,sbtable)
	for i,v in pairs(sbtable) do
		local exists = false
		for i,b in pairs(plr:FindFirstChild("SelectionBoxes"):GetChildren()) do
			local sb = b.Value
			if sb == v then
				exists = true
			end
		end
		if exists == false then
			local value = Instance.new("ObjectValue",plr:FindFirstChild("SelectionBoxes"))
			value.Name = "SelectionBox"
			value.Value = v
		end
	end
end)

Same issue here. Sent a table with a function from the server and got an empty table on the client.