Never made a pet for Roblox before and I started making it and I got it attached to the character and smoothly following the character around and all was good. I have the feeling I overlooked something as if my character dies since the pet is parented to the character so I can use Roblox’s own cleanup system to remove it I wonder what happened to the class it was assigned to. Eg. self.Pet = RS.PetFolder.SomePet:Clone().
Since that was only one part of the pet class table if Roblox cleans up the pet and a new pet is created using the PetModule.new() function what happens to the old PetClass metatable? Do I need to use some kind of cleanup?
You need to remove the reference to the class by setting it to nil, so the garbage collector can properly clean it up. Otherwise, it will just sit in memory as an unused class reference, which can lead to a memory leak. Make sure that when the player dies, you set all pet references to nil after running any necessary cleanup (like disconnecting connections and destroying the pet instance). Alternatively, you can create a class-based pet system that resets and recycles old class instances instead of creating new ones every time. This can help with performance and avoid unnecessary object creation.