I want to have all pets that have same name in the table DataObject[2], but my script only saves one of the pets. I look on other similar posts and they’re recommending using GenerateGUID but I don’t know how to implement that. Example of the script only saving one of the pets that has same name:
No programming languages (none that I know of) allows adding multiple identical indices. If you have “Pet1” index in a table, and you wish to add another value with the same name, you don’t get two “Pet1”'s, you overwrite the previous value of “Pet1”.
local t = {Pet1 = 1} -- expected
print(t.Pet1) -- 1
local t2 ={Pet1 = 1, Pet1 = 2} -- second Pet1 overwrites first Pet1.
print(t2.Pet1) -- 2
Not to mention, you can’t access two “Pet1”'s if using the same index for two values is even possible (save for pairs, but that lowers performance a bit, and that would be too much work to differentiate two same indices).
Would it be better for you to use the following structure?
Instead of creating a new index and setting the name of it to be the pets name, set it to the current index in the table + 1, and set the value to the amount of pets you have.