I would recommend using an OOP style module script for your system. But however you create it you’ll probably want to create a way to set a table for the amount of pets you have in the character for the equation. Create a function to be able to be referenced by the system with a script inside it with something like this:
local function GetBodyPosition(Pets--Table you set and store)
--Do the circular equation for each pet
return EquationResult
end
Then connect a function to the system for every time you add or remove a pet and have it call the function to get a new position for the pet.
You want to use some basic trigonometry here. Have it be where it selects a number from 0 to 1 then apply the coordinates to be the cosine and sine of whatever relative. I got a tutorial on this if u still confused
Yes, you make the function return the solution inside the function. So, say that you want to set the body position after creating the new pet. You would run the function as the body position property when setting it so it will return the body position and set it. It should looks like this.
[#Pets + 1] = Pet--Set the new pet's index number within the table's dictionary so it can be easily indexed.
local function GetBodyPosition(Pet)
local Position
local IndexNumber = 0
for I, V in next do
IndexNumber += IndexNumber
if V == Pet then
Position = CircularEquation(IndexNumber)
break
end
end
--[[
Use the dictionary index integer in a function to get the position based on its index integer and the total amount of pets currently in the table.
]]--
return Position
end
Pet.Model.PrimaryPart.BodyPosition.Position = GetBodyPosition(Pets[Pet])
--This will run the function with a parameter of the Pet's index integer so that it can get the position based off the returned value(result of the equation using the Pet's index integer.)
When you add a new Pet to the Pets table you should do this to make sure it’s added to the dictionary with an index integer. When you want to remove a pet use its integer from a saved value, or something like that.
It would be the equation for that part’s position out of how many pets are currently in the table. You would make a function that returns the value of the position based off the formula using the index integer in that post I sent in my first reply.
This would probably be the function for Pet.new in an OOP module script, but I’m talking about getting the position to set with a function inside of your pet system.
OOP just stands for Object Oriented Programming. That would be what I recommend you use for the structure of your system, but you don’t need to if you already have that setup.
Yes, you would have to create a function like that with the number of the children and the current child’s index integer to get the product of an equation from the post and then return it through that function.
Read the post in my first reply. They explain it in lots of detail and exactly how to get what you’re looking for. The only thing that they didn’t explain is how to implement it into your system which is what I explained in my replies. Did you read the post I’m talking about?
What I’m talking about is that when you create an OOP system in a module script you would create a function using their code for your situation and make it easier to access by doing so.
So say you have a module script and you require it every time the server wants to add a pet to a player’s character. You get the current pets saved within the character. Then you run the function from the module script to add a new saved pet and set its position using that persons code.
You could get the amount of pets and divide 360 or math.pi*2 by the amount of pets the player has currently in a for i pair loop so it’ll equal divide every pet around the player no matter how many they have