Ask a question!
Ep 57. Cannot unequip Pets
During the 57th episode we created and implementing the Notification system into our Simulator. Unfortunately, I made a mistake while creating the notification for telling the player that they cannot equip more pets. This mistake prevents players from using the unequip button to unequip a pet when they have equipped the maximum amount of pets they can equip.
Solution
The solution is quite simple. We should check if the selected pet is already equipped and if it is equipped or if more pets can be equipped, then we’ll fire the remote event.
StarterPlayer/StarterPlayerScripts/Gui/PetInventory.client.lua
Info.Buttons.Equip.MouseButton1Click:Connect(function()
SelectMode(false)
if selectedPet then
local equippedPets = #PetsConfig.GetEquippedPets(StateManager.GetData())
local maxEquippedPets = PetsConfig.GetMaxEquippedPets(StateManager.GetData())
local canEquip = equippedPets < maxEquippedPets
local isEquipped = StateManager.GetData().Pets[selectedPet]
if canEquip or isEquipped then
Remotes.EquipPet:FireServer(selectedPet)
else
Notifications.Create(`You can't equip more than {maxEquippedPets} pets!`)
end
end
end)