How to have multiple pets equipped

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

i have my pets inside the character, should i make a folder in them so i can loop through it

It’s up to you to decide that. My code was just example code to plan out your approach to the problem. Make it how you want it to work.

alr i’ll make sure to test that out

i did

local function setupPet(clone)
		local node = setPetNodes(amountEquipped, 1)
		
		for i, v in pairs(player.Character.EquippedPets:GetChildren()) do
			v:SetPrimaryPartCFrame(node[i].CFrame)
		end
		
		local attachChar = Instance.new("Attachment")
		attachChar.Visible = false
		attachChar.Parent = game.Players.LocalPlayer.Character.HumanoidRootPart

		local pos = Vector3.new(.5,.5,0) + clone.PrimaryPart.Size

		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[amountEquipped]
		alignPos.Responsiveness = 10
		alignPos.Parent = clone

		local alignOr = Instance.new("AlignOrientation", clone)
		alignOr.MaxTorque = 25000
		alignOr.Attachment0 = attachPet
		alignOr.Attachment1 = node[amountEquipped]
		alignOr.Responsiveness = 10
	end

and got an error " [Expected Attachment got Part for AlignPosition:Attachment1."

well i fixed the attachment thing now the problem is the pet getting sent too far but it works completely fine other than that

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.Transparency = 1
			currentNode.CanCollide = false
			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
	
	local function setupPet(clone)
		for i, v in pairs(player.Character.EquippedPets:GetChildren()) do
			
			local node = setPetNodes(amountEquipped, 1)
			
			local attachNode = Instance.new("Attachment")
			attachNode.Name = "AttachNode"
			attachNode.Visible = false
			attachNode.Parent = node[i]
			attachNode.Position = node[i].Position	
		
			local attachPet = Instance.new("Attachment")
			attachPet.Name = "AttachPet"
			attachPet.Visible = false
			attachPet.Parent = clone.PrimaryPart
		
			local alignPos = Instance.new("AlignPosition")
			alignPos.Name = "AlignPos"
			alignPos.MaxForce = 25000
			alignPos.Attachment0 = attachPet
			alignPos.Attachment1 = attachNode
			alignPos.Responsiveness = 10
			alignPos.Parent = clone
			
			local alignOr = Instance.new("AlignOrientation", clone)
			alignOr.Name = "AlignOr"
			alignOr.MaxTorque = 25000
			alignOr.Attachment0 = attachPet
			alignOr.Attachment1 = attachNode
			alignOr.Responsiveness = 10
			
		end
	end
1 Like