And when I go and apply this to the model it is slightly off.
local rotate=CFrame.Angles(table.unpack(string.split(object.CF_[2],",")))
local targetCFrame=CFrame.new(table.unpack(string.split(object.CF_[1],","))) * rotate
I am probably making a dumb mistake but please someone tell me!! CF_[1] is position and 2 is orientation just like I showed previously.
Thanks for reading and I hope yall can help.
First, let’s store the CFrame components more clearly and correctly:
object.CF_ = {
position = v.PrimaryPart.Position,
orientation = v.PrimaryPart.Orientation
}
Applying the CFrame
When you want to apply the CFrame back to the model, you should construct the CFrame and set it properly for all parts:
-- Parse the stored position and orientation
local position = Vector3.new(table.unpack(string.split(object.CF_.position, ",")))
local orientation = Vector3.new(table.unpack(string.split(object.CF_.orientation, ",")))
-- Create the target CFrame
local targetCFrame = CFrame.new(position) * CFrame.Angles(math.rad(orientation.X), math.rad(orientation.Y), math.rad(orientation.Z))
-- Move the model to the target CFrame
local primaryPart = object.PrimaryPart
-- Calculate the offset for each part relative to the primary part
for _, part in ipairs(object:GetDescendants()) do
if part:IsA("BasePart") then
local offset = primaryPart.CFrame:toObjectSpace(part.CFrame)
part.CFrame = targetCFrame:toWorldSpace(offset)
end
end
object.CF_ = {
position = v.PrimaryPart.Position,
orientation = v.PrimaryPart.Orientation
}
Applying
-- Directly use the stored position and orientation
local position = object.CF_.position
local orientation = object.CF_.orientation
-- Create the target CFrame
local targetCFrame = CFrame.new(position) * CFrame.Angles(math.rad(orientation.X), math.rad(orientation.Y), math.rad(orientation.Z))
-- Move the model to the target CFrame
local primaryPart = object.PrimaryPart
-- Calculate the offset for each part relative to the primary part
for _, part in ipairs(object:GetDescendants()) do
if part:IsA("BasePart") then
local offset = primaryPart.CFrame:ToObjectSpace(part.CFrame)
part.CFrame = targetCFrame:ToWorldSpace(offset)
end
end
I also tried printing CF_ but it returned as a blank table? This is the same thing that happened when I just straight up was setting the CF_ to .CFrame. I think the reason is that we’re setting the CF_ to a Vector3 value and not a string like I did here with a BasePart:
if object.CF_[2]~="0,0,0" then
-- it can only be 0,90,0 or 0,-90,0 or 0,180,0 or 0,-180,0, lets have preset rotations for those!
if object.CF_[2]=="0,90,0" then
print("90")
clone:SetPrimaryPartCFrame(clone:GetPrimaryPartCFrame() * CFrame.Angles(0,math.rad(90),0))
elseif object.CF_[2]=="0,-90,0" then
print("-90")
-- lets rotate the model
clone:SetPrimaryPartCFrame(clone:GetPrimaryPartCFrame() * CFrame.Angles(0,math.rad(-90),0))
elseif object.CF_[2]=="0,180,0" then
print("180")
clone:SetPrimaryPartCFrame(clone:GetPrimaryPartCFrame() * CFrame.Angles(0,math.rad(180),0))
elseif object.CF_[2]=="0,-180,0" then
print("-180")
clone:SetPrimaryPartCFrame(clone:GetPrimaryPartCFrame() * CFrame.Angles(0,math.rad(-180),0))
else
print(object.CF_[2])
end
end
Kinda bad solution but atleast it works lol Thanks for helping me you’re a W