Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I find the number of a certain type of pet inside a player's character?

I want to find out how many bunny pets are in someone's character for an un-equip system. Here's my code:

local thing = player.EquipedPets:WaitForChild("Pet"..#player.Character:WaitForChild("Bunny Pet"..))
   --^What can I put here that means anything?
player.Character:WaitForChild("Bunny "..thing.name):Destroy()								   

when you equip a pet It gets named with a number, for instance if you equip a bunny pet and you already have a pet equipped then it will be named "Bunny Pet1" (that whole system works just fine) What can I put at the comment the means something like "Any Character"? (as in any letter/number)

2 comments

0

So you want to know how how many Bunny Pets there are in a player's character? Just making sure I understand the question properly before answering

0

Yes.

1 answer

if lukesmasher is correct then if u want to print the number then you can do

for i,v in pairs(player.Character:GetChildren()) do
if v.Name:sub(1,5):match("Bunny") then
print(#v)
end
end

i believe this will print the amount if bunny's there are in the character

edit: not sure but i think this will just print a number instead of every pet name

5 comments

0

I think that solved it, but what does (1,5) do?

0

it starts at the first character in the name and stops at the 5th character and checks if the string match bunny

0

ok

0

This prints the name of the bunny pets. (If there are three bunny pets it prints )

0

"BunnyPet1", "BunnyPet2", "BunnyPet3"

This discussion is preserved as it was. New answers, comments, and votes are closed.