so basically when I made a pet equip script that seems to work fine but the problem is that it lets me equip the same exact pet twice and i found a solution where i have to give each of the pets a special id but i don’t know how i would
when i would click a picture in the inventory ui it would show in the “petinfo” section and when i press equip i made it so it clones the pet. i want to make it so that each of the pets have a special id as their “value” and the name of the value the pets name (im using a string value) so that when i select the one from the inventory section and i press equip it will equip that specific pet
so the most important thing is, how do i check how many things in a folder have the same name
ex:if there are 5 doggies in the folder than the fifths value is “5” etc
code
script.Parent.MouseButton1Down:Connect(function()
local petName = script.Parent.Parent.petName.Text
if game.ReplicatedStorage.Assets.Pets[petName] then
local petModel = game.ReplicatedStorage.Assets.Pets[petName]:Clone()
local positions = {
—not done
["1"] = 1,1,0,
["2"] = 2,1,0
}
local amountEquipped = #game.Players.LocalPlayer.EquippedPets:GetChildren()
if amountEquipped < 5 and petModel.Equipped.Value == false then
petModel.Equipped.Value = true
petModel.Parent = game.Players.LocalPlayer.Character
petModel:SetPrimaryPartCFrame(game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame)
local attachChar = Instance.new("Attachment")
attachChar.Visible = false
attachChar.Parent = game.Players.LocalPlayer.Character.HumanoidRootPart
attachChar.Position = Vector3.new(positions[amountEquipped + 1]) + petModel.PrimaryPart.Size
local attachPet = Instance.new("Attachment")
attachPet.Visible = false
attachPet.Parent = petModel.PrimaryPart
local alignPos = Instance.new("AlignPosition")
alignPos.MaxForce = 25000
alignPos.Attachment0 = attachPet
alignPos.Attachment1 = attachChar
alignPos.Responsiveness = 10
alignPos.Parent = petModel
local alignOr = Instance.new("AlignOrientation", petModel)
alignOr.MaxTorque = 25000
alignOr.Attachment0 = attachPet
alignOr.Attachment1 = attachChar
alignOr.Responsiveness = 10
local newPet = Instance.new("StringValue", game.Players.LocalPlayer.EquippedPets)
newPet.Name = petName
end
else
print("No text or no pet found")
end
end)