im working on a shop for my game, and i wanted to do “Add to cart” and then buy all ur items at once, kinda like online shopping
I was thinking for the cart, it would be a table, and when you add something to the cart it adds a objectvalue to the table. but how do i add a object value to a table?
If you have the ObjectValue instance, you can just use table.insert.
i dont, i have a model.
can i do Instance.new(“ObjectVal”) and then make its value be the model, then insert it?
Id rather have the object value NOT be in workspace, and jsut be in the script itself
tldr, yes you can set the value as a model
i know what a object value is, but how do i use table.insert to add the valeu
local myTable = {}
local objectValue = instance.new("ObjectValue")
objectValue.Value = script.Parent
table.insert(myTable, objectValue)
table.insert(Table, ObjectValue)

It works! and im assuming i can just fire a table through a event right?
Like as in FireServer(Table)
Yes, you can fire events with the table as a parameter like you’d do with any other value.
How do i clear a table? like table:clear() or somethin
table.clear(tableName) should work.
ok thanks thats all! char limit
Keep in mind that clearing a table doesnt destroy the instances that are inside the table. I would loop over the table, destroy the instances using :Destroy() and clear the table afterward.
This stays true as long as there is a reference to one of the values inside the table.
local ObjectValue = Instance.new("ObjectValue");
local Table = {};
table.insert(Table, ObjectValue);
table.insert(Table, Instance.new("ObjectValue"));
--// Reference variable to second object value
local SecondObjectValue = Table[2];
--// Clear the table
table.clear(Table);
--// Prints out "Value" and "Value"
print(ObjectValue.Name);
print(SecondObjectValue.Name);
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.