Having multiple 'pets' at once?

spawn(function()
	RunService.RenderStepped:Connect(function()		
		bg.CFrame = HumanoidRootPart.CFrame
		bp.Position = (HumanoidRootPart.CFrame * CFrame.new(GetPointOnCircle(5, 360/TotalPets))).p - Vector3.new(0, HumanoidRootPart.Size.Y / 2, 0) + Vector3.new(0, Duck.Size.Y, 0)		
		wait()
	end)
end)


They are all still inside each other. TotalPets is at 3

1 Like

I did update my GetPointOnCircle function, check you have the right one


Updated it, this is now the result. 2 of them are inside each other and the 3rd is off somewhere random? Idk where, but thats why the box is so large

1 Like

Make sure that when you do 360/NoOfPets you multiply it by the ith pet that you have equipped, so that with 3 pets it will be 120, 240, and 0, instead of all at 120

2 Likes

GetPointOnCircle(5, 360/TotalPets)

is what I have, with TotalPets == 3.

1 Like

Isn’t a BodyPosition a BodyMover?

2 Likes

oh im an idiot, didn’t realise his variable meant bodyposition/bodygyro

1 Like

When you loop through the code to change the position of each pet (supposedly) every frame, you’ll want to multiply 360/TotalPets by whatever no of pet that is, here’s how I did it

local RotationOffset = 360/#Pets

for i = 1, #Pets do
	local Pet = Pets[i]
	
	FollowScript(Pet, GetPointOnCircle(5, RotationOffset*i))
end

Note that follow script just does this

BodyPos.Position = (HumanoidRootPart.CFrame * CFrame.new(Pos)).p - Vector3.new(0, HumanoidRootPart.Size.Y / 2, 0) + Vector3.new(0, Head.Size.Y, 0)

where pet is the first parameter, and the second parameter is the offset I calculated from Unit Circle.

4 Likes

Kinda not sure how to properly implement that, ended up screwing with my script

function follow(Pet, Pos, bg, bp)
	spawn(function()
		RunService.RenderStepped:Connect(function()		
			bg.CFrame = HumanoidRootPart.CFrame
			bp.Position = (HumanoidRootPart.CFrame * CFrame.new(Pos)).p - Vector3.new(0, HumanoidRootPart.Size.Y / 2, 0) + Vector3.new(0, Pet.Size.Y, 0)
			wait()
		end)
	end)
end

function renderDuck(ducks)
	for _, v in pairs(ducks) do
		local PlayersDuck = Ducks['Tier ' .. v.Tier][v.Rarity]:Clone()
		PlayersDuck.Name = v.Tier .. ' - ' .. v.Rarity
		PlayersDuck.Parent = Character
		
		local Duck = PlayersDuck.Duck
		
		local bp = Instance.new('BodyPosition')
		local bg = Instance.new('BodyGyro')
				
		bg.D = 750
		bg.MaxTorque = Vector3.new(25000, 25000, 25000)
		bg.P = 5000
		
		bp.D = 400
		bp.MaxForce = Vector3.new(1250, 10000, 1250)
		bp.P = 2000
					
		bg.Parent = Duck
		bp.Parent = Duck
	
		Duck.Position = HumanoidRootPart.Position + Vector3.new(0, 10, 0)
		
		TotalPets = #ducks
		local RotationOffset = 360/TotalPets
		
		for i = 1, #TotalPets do -- ERROR HERE
			local Pet = TotalPets[i]
			
			follow(Pet, GetPointOnCircle(5, RotationOffset*i), bg, bp)
		end
	end
end

[ attempt to get length of upvalue ‘TotalPets’ (a number value)]

1 Like

Change the error line to

for i = 1, TotalPets do
1 Like

[ attempt to index upvalue ‘TotalPets’ (a number value)]

for i = 1, TotalPets do 
			local Pet = TotalPets[i]-- ERROR HERE
			
			follow(Pet, GetPointOnCircle(5, RotationOffset*i), bg, bp)
		end
1 Like

You’re attempting to get the index of the number of totalpets. You should change TotalPets[i] to where your pets are stored.

what you’re doing:

local Index = 1
local Pet = TotalPets[Index] -- yeah lol

what you should be doing:

local Index = 1
local Pet = AllPetsFolder[Index]
1 Like

I’d just change the entire script to this

function renderDuck(ducks)
	local RotationOffset = 360/#ducks
	
	for _, v in pairs(ducks) do
		local PlayersDuck = Ducks['Tier ' .. v.Tier][v.Rarity]:Clone()
		PlayersDuck.Name = v.Tier .. ' - ' .. v.Rarity
		PlayersDuck.Parent = Character
		
		local Duck = PlayersDuck.Duck
		
		local bp = Instance.new('BodyPosition')
		local bg = Instance.new('BodyGyro')
				
		bg.D = 750
		bg.MaxTorque = Vector3.new(25000, 25000, 25000)
		bg.P = 5000
		
		bp.D = 400
		bp.MaxForce = Vector3.new(1250, 10000, 1250)
		bp.P = 2000
					
		bg.Parent = Duck
		bp.Parent = Duck
	
		Duck.Position = HumanoidRootPart.Position + Vector3.new(0, 10, 0)
		follow(v, GetPointOnCircle(5, RotationOffset*_), bg, bp)
	end
end

Can you elaborate on what ducks is?

3 Likes
function follow(Pet, Pos, bg, bp)
	spawn(function()
		RunService.RenderStepped:Connect(function()		
			bg.CFrame = HumanoidRootPart.CFrame
			bp.Position = (HumanoidRootPart.CFrame * CFrame.new(Pos)).p - Vector3.new(0, HumanoidRootPart.Size.Y / 2, 0) + Vector3.new(0, Pet.Size.Y, 0)
			wait()
		end)
	end)
end

function renderDuck(ducks)
	local RotationOffset = 360/#ducks
	
	for _, v in pairs(ducks) do
		local PlayersDuck = Ducks['Tier ' .. v.Tier][v.Rarity]:Clone()
		PlayersDuck.Name = v.Tier .. ' - ' .. v.Rarity
		PlayersDuck.Parent = Character
		
		local Duck = PlayersDuck.Duck
		
		local bp = Instance.new('BodyPosition')
		local bg = Instance.new('BodyGyro')
				
		bg.D = 750
		bg.MaxTorque = Vector3.new(25000, 25000, 25000)
		bg.P = 5000
		
		bp.D = 400
		bp.MaxForce = Vector3.new(1250, 10000, 1250)
		bp.P = 2000
					
		bg.Parent = Duck
		bp.Parent = Duck
	
		Duck.Position = HumanoidRootPart.Position + Vector3.new(0, 10, 0)
		follow(Duck, GetPointOnCircle(5, RotationOffset*#ducks), bg, bp)
	end
end

Ok, ducks is

CurrentDucks = {
		[1] = {Tier = 1, Rarity = 'Common'},
		[2] = {Tier = 1, Rarity = 'Uncommon'},
		[3] = {Tier = 2, Rarity = 'Rare'},
	},

That’s what gets sent, so 3 spots, for 3 ducks basically

Still didnt work tho :confused: no error, all 3 inside each other

2 Likes

This line is probably causing your problems of moving one far away

Duck.Position = HumanoidRootPart.Position + Vector3.new(0, 10, 0)

This line here is probably causing your problems of them being inside one another

follow(Duck, GetPointOnCircle(5, RotationOffset*#ducks), bg, bp)

This is probably happening because multiplying RotationOffset (which you previously calculated to be 360/#ducks) by #ducks is just saying 360, or 0


Here’s what I made your code

function renderDuck(ducks)
	local RotationOffset = 360/#ducks
	
	for i, v in pairs(ducks) do
		local PlayersDuck = Ducks['Tier ' .. v.Tier][v.Rarity]:Clone()
		PlayersDuck.Name = v.Tier .. ' - ' .. v.Rarity
		PlayersDuck.Parent = Character
		
		local Duck = PlayersDuck.Duck
		
		local bp = Instance.new('BodyPosition')
		local bg = Instance.new('BodyGyro')
				
		bg.D = 750
		bg.MaxTorque = Vector3.new(25000, 25000, 25000)
		bg.P = 5000
		
		bp.D = 400
		bp.MaxForce = Vector3.new(1250, 10000, 1250)
		bp.P = 2000
					
		bg.Parent = Duck
		bp.Parent = Duck
	
		--Duck.Position = HumanoidRootPart.Position + Vector3.new(0, 10, 0)
		follow(Duck, GetPointOnCircle(5, RotationOffset*i), bg, bp)
	end
end
4 Likes


Still all inside each other

1 Like

Make sure that your GetPointOnCircle function is this

local function GetPointOnCircle(CircleRadius, Degrees)
	return Vector3.new(math.cos(math.rad(Degrees)) * CircleRadius, 0, math.sin(math.rad(Degrees)) * CircleRadius)
end

Try printing the return value to see if it’s any different each time (something like this)

local function GetPointOnCircle(CircleRadius, Degrees)
    print(CircleRadius, Degrees)
	return Vector3.new(math.cos(math.rad(Degrees)) * CircleRadius, 0, math.sin(math.rad(Degrees)) * CircleRadius)
end

edit: It’s all fixed, we did it in DMs. See Having multiple 'pets' at once? - #24 by OverHash for the solution to the problem

5 Likes

Don’t forget to mark the reply that fixed your problem as the solution.

2 Likes

Hey, Overhash.
I know this is over 1 year later, but I was wondering, if you know, how i’d get the circle to start in the back of my player, and not on the side, since it kinda triggers my ocd, that one side has more pets, than the other, when you have an uneven amount of pets. I’d like it to start in the back of my character, so that if the amount is uneven, the front will have more pets.

So, do you have any idea, how I’d change the starting point or just overall rotation of this circle?

Thanks.

Well the entire reason the pets circle around your character in the first place is because you’re positioning them around your HumanoidRootPart I assume. So just position it a little ways away from the Humanoid Root Part

1 Like