How to have multiple pets equipped

local Position = HumanoidRootPart.CFrame * CFrame.Angles(0,Angle,0) * PetOffset

should be…

local Position = HumanoidRootPart.CFrame * CFrame.Angles(0,Angle,0) * CFrame.new(0,0,math.clamp(OverlapMultiplier * #PetTable,4,math.huge)

The reason for the math.clamp is to prevent the pets from getting to close.

ah i see now, and then i just position the pets into “position”

Rather than:

math.clamp(OverlapMultiplier * #PetTable,4,math.huge)

Couldn’t you just do:

math.max(OverlapMultiplier * #PetTable, 4)

Oh yeah thanks for reminding me that those functions exist. I was wondering to myself if it does.

Sorry for the late reply but,

Heres my positioning code:

local clone = petModel:Clone()
		petModel.Equipped.Value = true
		clone.Parent = game.Players.LocalPlayer.Character
		clone:SetPrimaryPartCFrame(game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame)

		local attachChar = Instance.new("Attachment")
		attachChar.Visible = false
		attachChar.Parent = game.Players.LocalPlayer.Character.HumanoidRootPart
		attachChar.Position = --pos

		local attachPet = Instance.new("Attachment")
		attachPet.Visible = false
		attachPet.Parent = clone.PrimaryPart

		local alignPos = Instance.new("AlignPosition")
		alignPos.MaxForce = 25000
		alignPos.Attachment0 = attachPet
		alignPos.Attachment1 = attachChar
		alignPos.Responsiveness = 10
		alignPos.Parent = clone

		local alignOr = Instance.new("AlignOrientation", clone)
		alignOr.MaxTorque = 25000
		alignOr.Attachment0 = attachPet
		alignOr.Attachment1 = attachChar
		alignOr.Responsiveness = 10

how would i implent yours and @MattPrograms code into it

The code I posted was used to create the nodes for the pets to follow so you would need to use your AlignPostion and AlignOrientation code snippets and assign each pet to one of those nodes.

local alignPos = Instance.new("AlignPosition")
		alignPos.MaxForce = 25000
		alignPos.Attachment0 = attachPet
		alignPos.Attachment1 = attachChar --Instead of attaching to the character have it attach to one of the nodes
		alignPos.Responsiveness = 10
		alignPos.Parent = clone

		local alignOr = Instance.new("AlignOrientation", clone)
		alignOr.MaxTorque = 25000
		alignOr.Attachment0 = attachPet
		alignOr.Attachment1 = attachChar --Instead of attaching to the character have it attach to one of the nodes
		alignOr.Responsiveness = 10

i did

local function setPetNodes(petCount,overlapMultipler)
		local rotationOffset = 360/petCount --Determine how much degrees must be seperated between pets
		for petNode = 1,petCount do
			local currentNode = Instance.new("Part")
			currentNode.Name = "Pet Node "..petNode
			currentNode.Size = Vector3.new(1,1,1)
			currentNode.CFrame = CFrame.Angles(0,math.rad(rotationOffset*petNode),0) * CFrame.new(-game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector*math.max(petCount*overlapMultipler,4)) * game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
			local weld = Instance.new("WeldConstraint")
			weld.Parent = currentNode
			weld.Part0 = game.Players.LocalPlayer.Character.HumanoidRootPart
			weld.Part1 = currentNode
			currentNode.Parent = game.Players.LocalPlayer.Character
		end
	end
	
	local function setupPet(clone)
		local node = setPetNodes(amountEquipped, 1)
		
		local attachChar = Instance.new("Attachment")
		attachChar.Visible = false
		attachChar.Parent = game.Players.LocalPlayer.Character.HumanoidRootPart

		local pos = Vector3.new(1,1,0)

		attachChar.Position = pos

		local attachPet = Instance.new("Attachment")
		attachPet.Visible = false
		attachPet.Parent = clone.PrimaryPart

		local alignPos = Instance.new("AlignPosition")
		alignPos.MaxForce = 25000
		alignPos.Attachment0 = attachPet
		alignPos.Attachment1 = node
		alignPos.Responsiveness = 10
		alignPos.Parent = clone

		local alignOr = Instance.new("AlignOrientation", clone)
		alignOr.MaxTorque = 25000
		alignOr.Attachment0 = attachPet
		alignOr.Attachment1 = node
		alignOr.Responsiveness = 10
	end
	
	if amountEquipped < 5 and petModel.Equipped.Value == false and not game.Players.LocalPlayer.EquippedPets:FindFirstChild(petStringv) then
		amountEquipped += 1
		local clone = petModel:Clone()
		petModel.Equipped.Value = true
		clone.Parent = game.Players.LocalPlayer.Character
		clone:SetPrimaryPartCFrame(game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame)

		setupPet(clone)

		local newPet = Instance.new("StringValue", game.Players.LocalPlayer.EquippedPets)
		newPet.Name = petName
		newPet.Value = game.Players.LocalPlayer.PlayerGui.GameGui.Inventory.PetInfo.PetView[clone.Name].Value
	end

but it just spawns in a part that follows me

i would really appreiciate it if you could go a little more into detail on this because im not fully understand how to do it,

i dont know where to place all the functions that you and @MattPrograms made
i dont know what to assign to what
etc

The function I provided was just used to position the nodes that the pets should use to follow the player. Basically you should call the function whenever a player changes the number of pets they have equipped to fit for the required amount of pets.

1 Like

so how do i position the pets in the right place, as i said, it just makes a small part that follows the player

I was explaining that here. Make the pets AlignPosition and AlignOrientation be set to follow one of the nodes (aka the parts that my function was creating).

i did do that,
with the pet unachored it just falls out of the map and with it anchored it doesn’t do anything

What are the current properties of your AlignPosition? Since if they are to weak it’s going to cause issues. I would also recommend making the pets massless.

25000 max force

massless anchored or massless unanchored?

also another question i’ve been meaning to ask is what is overlap multiplier and do i use the script that @MattPrograms made in this, if so where

The OverlapMultiplier was a parameter to change the radius of the circle in which the nodes were generated. It was there to give some wiggle room depending on how big your pets are.

I think the issue is that you keep trying to do local node = setPetNodes(amountEquipped, 1) which is flawed since my function doesn’t return any value as it stands right now. If you would want this to work you would need to modify my function to add add each node in the for loop to a table and return that at the end of the function.

i see, so how could i do this without having to modify your function (the for loop returning)

It would be a messier approach but all of the Node Parts are parented in the Player’s Character. It would not be an ideal approach. If you want like I can modify the function to return the table of nodes.

ok i would appreciate that, this whole thing has me confused

Now when using this function it’s going to return a table so when assigning pets to each node you will need to iterate over the table to assign each to pet to one of the nodes.

local function setPetNodes(petCount,overlapMultipler)
	local rotationOffset = 360/petCount --Determine how much degrees must be seperated between pets

    local = nodeTable = {}
	for petNode = 1,petCount do
		local currentNode = Instance.new("Part")
		currentNode.Name = "Pet Node "..petNode
		currentNode.Size = Vector3.new(1,1,1)
		currentNode.CFrame = CFrame.Angles(0,math.rad(rotationOffset*petNode),0) * CFrame.new(-game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector*math.max(petCount*overlapMultipler,4)) * game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
		local weld = Instance.new("WeldConstraint")
		weld.Parent = currentNode
		weld.Part0 = game.Players.LocalPlayer.Character.HumanoidRootPart
		weld.Part1 = currentNode
		currentNode.Parent = game.Players.LocalPlayer.Character
        table.insert(nodeTable,currentNode)
	end
    return nodeTable
end