How to show pets as equipped on ui when loading back in

Video

local EquippedPetsDataString = EquippedPetsData:GetAsync(plr.UserId)
	
	if EquippedPetsDataString ~= nil then
		for i,v in pairs(EquippedPetsDataString) do
			local NewPodEquippedData = Instance.new("StringValue", plr.EquippedPets)
			NewPodEquippedData.Name = tostring(v)
			
			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
		end
	end

the code that loads in pets back into workspace.

function UpdatePlayersPets(NewPet)
	local cloendpet = NewPet:Clone()

	local clonedTemplate = script.PetButtonUi:Clone()
	clonedTemplate.Name = cloendpet.Name
	clonedTemplate.Parent = script.Parent.PetInventoryFrame.Frame.innerFrame.PetButtonHolder
	cloendpet.Parent = clonedTemplate.PetModelHolder

	local NewCam = Instance.new("Camera", clonedTemplate)
	clonedTemplate.PetModelHolder.CurrentCamera = NewCam
	clonedTemplate.Name = cloendpet.Name
	clonedTemplate.PetName.Text = cloendpet.Name
	clonedTemplate.PetMulti.Text = "x"..cloendpet.Multiplier.Value

	NewCam.CFrame = CFrame.new(cloendpet.PrimaryPart.Position)

the code that creates the templates when player rejoins.


task.wait(4)
for i,v in pairs(plr.Pets:GetChildren()) do
	if v:IsA("StringValue") then
		local Pet = game.ReplicatedStorage.PetIndex[v.Name]
		UpdatePlayersPets(Pet)
	end
end


the code that loops through pets and calls the function.

You could try checking if the pets are equipped when player clicks their inventory

1 Like

i will try this now thanks for the reply!

1 Like

this works so thank you but it equips the wrong pets.

i have a folder for the equipped pets as you can see but it seems to equip the dogs instead


script.Parent.Hud.PetFrame.PetIconButton.MouseButton1Down:Connect(function()
	
	for i,v in ipairs(script.Parent.PetInventoryFrame.Frame.innerFrame.PetButtonHolder:GetChildren()) do
		if v:IsA("Frame") and #plr.EquippedPets:GetChildren() ~= nil then
			if plr.EquippedPets:FindFirstChild(v.Name) and petsallowed <= plr.PetsEquippedNumber.Value -1 then
				v.Equipped.Value = true
				v.UIStroke.Color = Color3.fromRGB(80, 255, 61)
				v.TickIcon.Visible = true
				print("FOne")
				petsallowed += 1
				wait(1)
			end
		end
		
	end
end)



this is the code for it. im not sure if it has something to do with them having the same name maybe?

May I ask, what are the children you are looping through in this for loop?

(script.Parent.PetInventoryFrame.Frame.innerFrame.PetButtonHolder:GetChildren())
2 Likes

the pet button holder is what has the pet templates in it

image
it has every pet in the inventory in it.

I have fixed the issue thank you everyone for your responses! :slight_smile:

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