#Help with pet storage system

1 messages · Page 1 of 1 (latest)

analog turtle
#

I'm making a pet storage system that uses numbers to distinguish between pets of the same name. It checks the pet name using the while function in the lua block then adds the pet name to a string instance used to store the player's inventory. The problem is that it works well until there are 3 pets of the same name. Then all new pets are given the name "Pet2"

         if plrpets:FindFirstChild(petresult) then
            print("Replica Found")
            while plrpets:FindFirstChild(petresult) do
                print(int)
                int +=1
                petresult = petresult..tostring(int)
            end
            petinstance.Name = petinstance.Name..tostring(int)
            int = 0
            petinstance.Parent = plrpets
        else
            petinstance.Parent = plrpets
        end
onyx basin
#
while plrpets:FindFirstChild(petresult) do
                print(int)
                int +=1
                petresult = petresult..tostring(int)
            end```
lol
output: petresult = petresult..tostring(1) = "x1"
output: petresult = petresult..tostring(2) = "x12"
output: petresult = petresult..tostring(3) = "x123"
output: petresult = petresult..tostring(4) = "x1234"
analog turtle
#

but ofc broken bec of the 1234

onyx basin
#

coz you keep appending the next number

#

and then you throw it out lol petinstance.Name = petinstance.Name..tostring(int)

analog turtle
#

but I would only need the last number of the sequence no?

#

so the very last updated value of int will be the last number of the sequence

onyx basin
analog turtle
#

yes

onyx basin
#

or did you get it from ai?

analog turtle
#

nope i wrote it

onyx basin
# analog turtle nope i wrote it

can you tell me what this is for? lua while plrpets:FindFirstChild(petresult) do print(int) int +=1 petresult = petresult..tostring(int) end

analog turtle
#

well let's say there's a pet named dog

#

plrpets is a form of storage I use for the player's inventory. It's a folder containing a list of strings. Each string is the name of a pet

#

so in the while loop it checks if there's a pet called dog. if there's a pet called dog it changes the name to dog1 then checks that name again

#

then it repeats for dog1 ,dog2, dog 3 and so on

hearty atlasBOT
#

studio** You are now Level 2! **studio

onyx basin
analog turtle
#

oh i see

#

that's the fix thanks

onyx basin
#

unintentionally, no doubt

analog turtle
#

yh i see it now. I think it's better to remove the number with each loop or change the way it finds the pet name. Thanks for your help

onyx basin
#

remember, the only difference between broken and working as intended is, by definition, your intention. that's where you need prints and such. don't assume your code is working properly, in fact you should assume the opposite by default. and when you do print, print everything

#

breakpoints are even better