Since releasing my 100 free simulator pet models one of my most persistent requests was to make a script which makes pets follow the player, so here we are.
System in action (Ignore bad gif quality)
API: :AddPet(Player, PetName) Searches the pet folder for a pet by that name. :AddPet(PetName) Also works and automatically assigns the pet to the local player. :RemovePet(Player, PetName) Searches the players existing pets and removes a pet by that name. :HidePets(Player) Hides that players pets from view and stops performing movement calculations on them :HideOtherPets() Hides all pets except the local players from view and stops performing movement calculations on them :HideAllPets() Hides all pets from view and stops performing movement calculations on them :ShowPets(Player) Shows that players pets and continues movement calculations on them :ShowOtherPets() Shows every players pets and continues movement calculations on them excluding the local player :ShowAllPets() Shows all pets and continues movement calculations on them
Settings (Located in settings module) PetFolder - Folder where your pet models should be located OtherPetsVisible - If you can see the pets of players who join AllPetsVisible - Mostly for internal stuff, but if false it overrides 'OtherPetsVisible'. YDrift - The max change on the Y axis that the pet will drift up and down, YDriftSpeed - The speed at which the pet drifts on its Y axis, Responsivness - How quickly the pets respond to movement by the player, Radius = How far away [In studs] the pets orbit around the player,
local PetFolder = game.Players.LocalPlayer:WaitForChild('PetFolder') local HideOthersButton PetFolder.ChildAdded:Connect(function(Child) PetModule:AddPet(Child.Name) end) PetFolder.ChildRemoved:Connect(function(Child) PetModule:RemovePet(Child.Name) end) HideOthersButton.MouseButton1Click:Connect(function() PetModule:HideOthersPets() end)
And just like that in 13 lines of code you have set up a pet following system!
Going to be honest I’ve barely done any testing on the API excluding the AddPet function so it is possible they will not work, if so let me know and ill update it when I get the chance.
The pet model must have a primary part else the module will break, in addition to that my module performs no validation checks on the functions you are calling so if you try to add an invalid pet it will error.
I strongly recommend disabling cast shadow for your pets, having hundreds of moving objects is bad enough without having to worry about the lighting engine.
I strongly recommend not having an excess of maybe 300 pets loaded at a time, while I believe my module is pretty performant I would not recommend doing anything stupid with it.
I don’t think I mentioned this in the post since I thought it was obvious but evidently it has caused confusion this module must be run on the client, it may work on the server but it is designed to be used on the client.