Convert CFrame into Vector3?

Hello, I have been working on a pet following system but I am using CFrames and I want to convert that CFrame to a Vector3 to use bodypositions here is my script (from this post’s solution: Make revolving parts around a character):

local module = {}

local folder = script.Folder.Value
local RunService = game:GetService('RunService')

local fullCircle = 2 * math.pi
local radius = 5


function module.EquipPet(player, petName)
    local character = player.Character or player.CharacterAdded:Wait()
    local hrp = character:WaitForChild('HumanoidRootPart')
    local pet = folder:FindFirstChild(petName):Clone()
    pet.Parent = character:WaitForChild('Pets')


    local function getXAndZPositions(angle)
        local x = math.cos(angle) * radius
        local z = math.sin(angle) * radius
        return x, z
    end
    
    RunService.Heartbeat:Connect(function()
        for i, v in pairs(character.Pets:GetChildren()) do
            local angle = i * (fullCircle / #character.Pets:GetChildren())
            local x, z = getXAndZPositions(angle)

            local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
            local lookAt = hrp.Position
            local pos = CFrame.new(position, lookAt)
            v.PrimaryPart.BodyPosition.Position = pos
        end
    end)
end

return module

But it does not work so I need to find a way to convert this CFrame Value into a Vector3: local pos = CFrame.new(position, lookAt) How can I do that?

Thank you!

4 Likes

If I want to use bodygyros too how can I do that?

1 Like

cframes have a property that is called “Position”, which gets the position (a Vector3) of the CFrame. All you need to do is:

CFrame.Position
26 Likes

Thank you ! It works perfectly !

1 Like