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.
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.
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
end
end
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)
end
if EquippedPetsDataIndex ~= nil then
EquippedPetsData:SetAsync(plr.UserId, EquippedPetsDataIndex)
end
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
end
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()
end
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
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.