Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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)

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 LukeSmasher 619 — 4y
0
Yes. MasonTheCoolBean8 -2 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

0
I think that solved it, but what does (1,5) do? MasonTheCoolBean8 -2 — 4y
0
it starts at the first character in the name and stops at the 5th character and checks if the string match bunny Gameplayer365247v2 1055 — 4y
0
ok MasonTheCoolBean8 -2 — 4y
0
This prints the name of the bunny pets. (If there are three bunny pets it prints ) MasonTheCoolBean8 -2 — 4y
0
"BunnyPet1", "BunnyPet2", "BunnyPet3" MasonTheCoolBean8 -2 — 4y
Ad

Answer this question