for some reason when i send a table to a server the server sees it as nil even though there is elements inside of it (instances) a gui frame
heres the local script
local Products = {}
script.Parent.ChildAdded:Connect(function(child)
wait(0.1)
table.insert(Products, child)
end)
script.Parent.ChildRemoved:Connect(function(child)
wait(0.1)
for i,v in pairs(Products) do
if v.Name == child.Name then
table.remove(Products, i)
print(Products)
return
end
end
end)
script.Parent.Parent.Parent.PurchaseButton.MouseButton1Click:Connect(function()
print(Products)
game.ReplicatedStorage.Event.SendToServerProduct:FireServer(Products)
end)
Are the instances created on the client? If so, the server cannot see them.
You are only adding to the table on ChildAdded, but the children may already be there. You should loop through the current children and add them to the products table.
Instances created in a LocalScript will be created on the client and not replicated to the server for security. To create them on the server, create them in a Script (server script) instead.
i just fixed it , instead of putting the instance in the table i will just add the name which will be a string for anyone who is curious on the solution here it is
local script
local Products = {}
script.Parent.ChildAdded:Connect(function(child)
wait(0.1)
table.insert(Products, child.Name)
end)
script.Parent.ChildRemoved:Connect(function(child)
wait(0.1)
for i,v in pairs(Products) do
if v.Name == child.Name then
table.remove(Products, i)
print(Products)
return
end
end
end)
script.Parent.Parent.Parent.PurchaseButton.MouseButton1Click:Connect(function()
print(Products)
game.ReplicatedStorage.ZeamzorEvents.SendToServerProduct:FireServer(Products)
end)