How would pets with the same name show as equipped? (please help)

function UpdateEquippedp()
	local hasran = false
	local Pet1 = plr.PetEquipped1.Value
	if Pet1 ~= "" then
		local button = script.Parent.PetInventoryFrame.Frame.innerFrame.PetButtonHolder:FindFirstChild(Pet1)
		button.Equipped.Value = true
		button.UIStroke.Color = Color3.fromRGB(80, 255, 61)
		button.TickIcon.Visible = true
		button.SelectionOrder = 1
	local Pet2 = plr.PetEquipped2.Value
	if Pet2 ~= "" then
		local button1 = script.Parent.PetInventoryFrame.Frame.innerFrame.PetButtonHolder:FindFirstChild(Pet2)
	button1.Equipped.Value = true
	button1.UIStroke.Color = Color3.fromRGB(80, 255, 61)
	button1.TickIcon.Visible = true
		button1.SelectionOrder = 1

	local Pet3 = plr.PetEquipped3.Value
	if Pet3 ~= "" then
		local button2 = script.Parent.PetInventoryFrame.Frame.innerFrame.PetButtonHolder:FindFirstChild(Pet3)
	button2.Equipped.Value = true
	button2.UIStroke.Color = Color3.fromRGB(80, 255, 61)
	button2.TickIcon.Visible = true
		button2.SelectionOrder = 1


Code that sets that shows pet equipped in ui.

video with my issue.

( i have been trying to do this for 4 days i am going insane i cannot cope with this for much longer)
(i have already gone insane it is too late.)

You can use HttpService:GenerateGUID to assign a unique identifier to each pet. This will allow you to not rely on the names given to each pet. You can then use that identifier to check which pet is equipped and which isn’t.

1 Like

thank you i will do this, however would i need to save this in a datastore or no? or just create it when the player joins? should i put this inside the pet template when its created? because i have an equipped bool inside of the pet model and the pet template(button)

If your game saves the pets, and especially if it saves which pet was equipped when a player left the game previously, it would be advisable that you store the GUID’s linked to the specific pet.

it just loops through the pet folder inside of replicatedstorage should i save the pets as an actual model inside a folder? and also save the Guid that is inside that pet?

I would recommend you only save the GUID and use that to determine which pets need to be equipped. Essentially, you want to make a dictionary where the GUID is the key and the pet object is the value.

Here are two ways you could tackle this:

    ['{D8FEEA26-D7AB-4D72-8C43-0DB44C5EC791}'] = Instance,
    ['{D59ECAB3-6E88-4939-9984-FE83A6A7FD82}'] = Instance
    ['{D8FEEA26-D7AB-4D72-8C43-0DB44C5EC791}'] = {Object = Instance, Equipped = false},
    ['{D59ECAB3-6E88-4939-9984-FE83A6A7FD82}'] = {Object = Instance, Equipped = true}

will try this later thank you just gonna show you my code so you can see whats going on data wise.

	local EquippedPetsDataString = EquippedPetsData:GetAsync(plr.UserId)
	if EquippedPetsDataString ~= nil then
		for i,v in pairs(EquippedPetsDataString) do
			local Newpet = game.ReplicatedStorage.PetIndex[tostring(v)]:Clone()
			Newpet.Parent = workspace.Player_Pets:FindFirstChild(plr.Name)
			plr.PetMultiplier.Value += Newpet.Multiplier.Value
			plr.PetsEquippedNumber.Value += 1

in the server script this is what loads in the pets

local EquippedPetsDataIndex = {}
	for i,Pe in pairs(plr.EquippedPets:GetChildren()) do
		table.insert(EquippedPetsDataIndex, Pe.Name)

	if EquippedPetsDataIndex ~= nil then
		EquippedPetsData:SetAsync(plr.UserId, EquippedPetsDataIndex)

saving it this is what it does.

	local Guid = game:GetService("HttpService"):GenerateGUID()
	plr.PetMultiplier.Value += clonedPet.Multiplier.Value
	if plr.PetsEquippedNumber.Value == 0 then
		plr.PetsEquippedNumber.Value = 1
		plr.PetEquipped1.Value = Guid
	elseif plr.PetsEquippedNumber.Value == 1 then
		plr.PetsEquippedNumber.Value = 2
		plr.PetEquipped2.Value = Guid
	elseif plr.PetsEquippedNumber.Value == 2 then
		plr.PetsEquippedNumber.Value = 3
		plr.PetEquipped3.Value = Guid

i just tried this, this is the code that fires when you equip a pet.

local result = game.ReplicatedStorage.EquipPet:InvokeServer(SelectedPet)
				if result == true then
					clonedTemplate.Equipped.Value = true
					clonedTemplate.UIStroke.Color = Color3.fromRGB(80, 255, 61)
					clonedTemplate.TickIcon.Visible = true
					clonedTemplate.SelectionOrder = 1
					script["Successful Sound Effect"]:Play()

this is what it returns changing the color.

could you try and modify my code so i can understand easier? sorry just i have adhd so i struggle to focus on these things Lol

1 Like

You could create an Attribute, you can add right to each pet. This could be your identifier as apposed to using the pet name.

how would i make the pet button to show as equipped though and where do i add this the pet model or the pet template (aka the button you click to equip the pet)?

Maybe I misunderstood your question. This is just a way to have something to reference that would always be unique to that pet. You add Attributes to the pet itself in the studio.