function renderDuck(ducks)
for _, v in pairs(ducks) do
local PlayersDuck = Ducks['Tier ' .. v.Tier][v.Rarity]:Clone()
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)
spawn(function()
RunService.RenderStepped:Connect(function()
bg.CFrame = HumanoidRootPart.CFrame
bp.Position = CFrame.new(HumanoidRootPart.CFrame * Vector3.new(0, 2, 4)).p
wait()
end)
end)
end
end
The problem I am having is it is creating all of the ducks inside of each other. So I want to know if thereās a way to spread them randomly, like how other games utilize pets
I think what the other game is referring to is an infinite number of pets to collect, not equip otherwise a player would spam equip them and make everything super unpleasant.
Iām not the best at this sort of stuff so if anyone has anything to add to this code, feel free Iād love to learn more too!
local Amount = 3
local Positions = {
[1] = "0, 0, 10", -- i'm not 100% sure on how you should properly save these numbers with string or without
[2] = "0, 0, 0",
[3] = "0, 0, -10",
}
for index, v in next, EquippedPets:GetChildren() do
if Amount >= 0 then
Amount = Amount - 1
local pet = v:Clone()
pet.Parent = workspace
pet.Position = Vector3.new(tonumber(Positions[index])) -- I'm not on studio so I'm not sure if this is how you will reference this position
end
else
print('Max pets')
end
I havenāt tested this out so let me know, this is just a basic draft that I made on the top of my head. Apologies if it isnāt what you wanted.
local function GetPointOnCircle(CircleRadius, Degrees)
return Vector3.new(math.cos(math.rad(Degrees)) * CircleRadius, 0, math.sin(math.rad(Degrees)) * CircleRadius)
end
From there I got the number of pets, and did 360/NoOfPets, then simply moved the pet to
-- Pos is the GetPointOnCircle
BodyPos.Position = (HumanoidRootPart.CFrame * CFrame.new(Pos)).p - Vector3.new(0, HumanoidRootPart.Size.Y / 2, 0) + Vector3.new(0, PetHead.Size.Y, 0)
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
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