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 would like to know how to prevent that. When i click a gui in an inventory it brings up this ‘petinfo’ and when you press equip it equips but if you press equip multiple times on that same pet it will equip
I tried making an equip value in it but i clone the original pet which has it set to false so that doesnt work
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 = {
["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)