Saving and loading pets with unique id's?

I’m currently creating a pet system where it saves and loads pets. I’ve figured out that you shall never save pets only using their name due to many problems, but with a unique id and name instead (table).

The question is if I should save and load pets using HttpsService with the GUID feature. Would that be an alright method for saving and loading unique pets? (I am curious since I haven’t seen anyone post anything about GUID pet saving here on the dev forum)

-- Which of these tables would be essential to store in an inventory, if I use the GUID method?
PlayersDataInventory = {
	["Dog"] = "9FB74F07-67DD-4E0F-8C9C-11AD2B85B93D"
}

PlayersDataInventory = {
	["1F22864F-8E5B-47A8-A1B3-D424E170B361"] = "Dog"
}
1 Like

Yes. If you ever thought about pets having the same id, this would be your best bet to counter that. The chance of the same GUID being duplicated is so incredibly low its basically impossible. TL;DR, yes, this is a completely fine way of saving/loading unique pet ID’s, since it’s easy to find and use.

2 Likes

Perfect, which way of storing it would you prefer of the two examples I showed?

I prefer the first method, since it would be easier to use.

1 Like

I would also recommend making something that is based on values like a timestamp or the configuration / properties of something. That way since timestamps always change and configurations may vary, it will always be unique.

1 Like

The whole point of having unique id’s is so the player doesn’t get the same data twice and so it removes the old one.

To elaborate on what I am saying :

-- Let's say I'm using your first way of saving the pets data : 
-- Player1 gets the pet "Dog" and so it's saved in their inventory.
local PlayersDataInventory = {
   ["Dog"] = "9FB74F07-67DD-4E0F-8C9C-11AD2B85B93D"
}

5 minutes have passed, what’s that? Player1 got another dog?!
Let’s add it to Player1’s inventory again.
Now this is the main issue, the inventory table already has the key “Dog” and setting it again will overwrite the old data and so instead we use a different key for the second Dog.

There are many ways to combat this :

  1. You either save the dogs in a table rather than just giving them an id
  2. You just set the key as the ID rather than the name
2 Likes

I use the second method - I store a small table of data about the object’s attributes, with the key being the unique ID, for example:

Inventory = {
	["UNIQUEIDHERE"] = {
		ItemId = "DOG",
		...
	}
}

(And depending on how many pets the player could possibly obtain, you should also try to condense the amount of characters used in save data, to save space)

4 Likes

A player in my game with a maxed out inventory (with all inventory gamepasses) would get the inventory characters up to 67 360‬ characters + 27 365‬ characters in the attributes due to (Pet Type) saving :scream:

How could I potentially save the pets with an unique ID, but with fewer characters than 32?

Do I shorten the GUID after I generate one? (wouldn’t this give a bigger risk for the key having the same GUID?)

Or do you have another method for this?

Yeah, I would shorten the GUID. After generating a GUID, I first check if that GUID already exists in the player’s data, and if it does, I try generating a new one again. That way you’ll never have to worry about any collisions.

3 Likes