How to avoid having two values be the same

All of this is a part of my pet system. Every new pet that the player opens gets a uuid. This pet is stored inside the player. The pet is also stored inside the playergui so you can see the pets you have. The pet inside the player and the pet inside the playergui both have a uuid. My goal is to set the pet’s uuid inside the PLAYERGUI to the same as the pet’s uuid inside the PLAYER. The problem is if 2 pets have the same name then both of them will have the same uuid which is not what I want.

The first for loop is for setting the values, the second for loop is for checking if the value is the same.

for i, Pet in pairs(Player.PetInventory:GetChildren()) do
	if Pet.Name == newTemplate.Name then
		for i2, Pet2 in ipairs(Player.PlayerGui.Inventory.Pets.ScrollingFrame:GetDescendants()) do
			if Pet2.Name == "UUID" then
				newTemplate.UUID.Value = Pet.Value
			end
		end
	end
end

for i, Pet in pairs(Player.PetInventory:GetChildren()) do
	if Pet.Name == newTemplate.Name then
		for i2, Pet2 in ipairs(Player.PlayerGui.Inventory.Pets.ScrollingFrame:GetDescendants()) do
			if Pet2.Name == "UUID" then
				if Pet2.Value ~= Pet.Value then
					newTemplate.UUID.Value = Pet.Value
				end
			end
		end
	end
end

I mean this is kinda jank but you can attach a number to the end of the uuid and then index it later. For example, if the uuid is “asdf”, check all the other pets and if there is a uuid that is the same, make the uuid “asdf.0” or something like that.

That’s not really a problem. Even if the pet has the same name, they already have different UUIDs in the player’s pet inventory. The issue is that I can’t work out the in pairs loops to set those uuids to the player’s playergui.

Well in that case just do the same thing for the pet names. Have it like “Pet.0” or something and use string.split() to separate it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.