Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I save pets with different levels?

Hi! So usually for saving inventories, I would make a table and add the tool Name to it. Then to load data I would just go through the data, check if there’s a tool of that name in the tools folder, then clone it into the players backpack. However, pets are different as they have data like levels etc. I was going to use dictionaries but what if the player has 2 pets of the same name? Then the dictionary key will be messed up. This is what I mean:

--Player has 2 dogs
local pets = {
      ["Dog"] = {["Level"] = 4,["Exp"] = 6},
       ["Dog"] = {["Level"] = 2,["Exp"] = 3} -- There are 2 dog keys which will mess up the system!
}

How would I go about with saving pets?

1 answer

you are very close to how it could work

	local pets = {
		Dog = {
			[1] = {
				Level = 5,
				Exp = 20
			},
			[2] = {
				Level 5,
				Exp = 20
			}
		},
	}

you could do it this way using mixed tables to not mess keys up, make a for loop to go through each pet and use an index loop to go through the array to get their data

this might not be THE best way but it is a working way

This discussion is preserved as it was. New answers, comments, and votes are closed.