I am looking to find the amount of a specific card within a table that I’ve made. This is because if the player only has 2 cards in their deck, I don’t want them to be able to equip more than that, so I want to check their equipped cards for how many of the same card they have and check if that number is the same or less than how many of that card they have in their deck.
#insertTableNameHere
returns the total amount of things within a table, and table.find()
just returns the first index of whatever you enter into it, and not the quantity of things within that table.
I’ve run into a problem here in my EquipCard
function where I’m not sure how to check if the player has enough cards to equip more than one. In my third if
check, I’m preventing the player from equipping more than one if they only have one of that card in their deck, but if they only have two of a card, nothing is stopping them from equipping four of that card.
Sorry for the long explanations as I wasn’t sure how to best describe my problem.
function DeckClient.EquipCard(cardName, cardHovered: ImageButton)
local card: Types.Card = DeckClient.RetrieveCardInDeck(cardName)
if card == nil then return end
if #equippedCards >= 4 then return end
if table.find(equippedCards, card) and card.CardAmount == 1 then return end
table.insert(equippedCards, card)
local equippedCardIcon = RS.CardsGui.EquippedCard:Clone()
equippedCardIcon.Image = "http://www.roblox.com/asset/?id=" .. card.ImageId
equippedCardIcon.Name = "EquippedCard" .. #equippedCards
equippedCardIcon.Parent = equippedCardsList
end