-
What do you want to achieve? I want to check if a player character has the same accessory multiple times.
-
What is the issue? I can’t manage to do it.
-
What solutions have you tried so far? I tried to do it myself and looked on forums.
By that do you mean if they own duplicates of an item?
Yes, i mean that
(character limit)
how are the items stored, are they like tools in player’s backpack or something? You need to give more precise info
Well accessories, they are inside the player character
You would just do something like that (this just counts the amount of accessories in the player character, I hope i got the problem right):
local allAccessories = {}
for _, accessory in ipairs(character:GetChildren()) do
if not accessory:IsA("Accessory") then continue end
if not allAccessories[accessory.Name] then
allAccessories[accessory.Name] = 0
end
allAccessories[accessory.Name] += 1
end
to check if a specific accessory is in the character multiple times just do this:
local accessoryName = "Accessory"
function checkHowMuchDuplicates(name : string)
local amount = 0
for _, accessory in ipairs(character:GetChildren()) do
if not accessory:IsA("Accessory") or accessory.Name ~= accessoryName then
continue
end
amount += 1
end
return amount
end
print(checkHowMuchDuplicates(accessoryName))