How do I change the Orientation for a CFrame [Solved]

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to change the Orientation of an Attachment, using AttachmentPoint
  2. What is the issue? Include screenshots / videos if possible!
    Everytime I try to change the orientation it tells me that orientation is not a part of CFrame
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried changing the Orientation to LookVector, Using CFrame.Angle but I keep getting the same error, I am un sure where to proceed from this point as every solution I try doesn’t seem to work.
local function applyAppearance(dummy, normalData, superHeroData)
	local slotData = superHeroData or normalData

	if not slotData then
		return
	end

	for slotName, slotValue in pairs(slotData) do
		print("Slot Name:", slotName)
		print("Slot Value:", slotValue)
		if slotName == "BodyColor" then
			local bdc = Instance.new("BodyColors")
			bdc.Name = "BodyColor"
			bdc.HeadColor3 = Color3.fromHex(slotValue)
			bdc.LeftArmColor3 = Color3.fromHex(slotValue)
			bdc.LeftLegColor3 = Color3.fromHex(slotValue)
			bdc.RightArmColor3 = Color3.fromHex(slotValue)
			bdc.RightLegColor3 = Color3.fromHex(slotValue)
			bdc.TorsoColor3 = Color3.fromHex(slotValue)
			bdc.Parent = dummy
		elseif slotName == "FirstHair" then
			local hairModel = game.ReplicatedStorage.Hair1[slotValue]
			if hairModel then
				local newHair = hairModel:Clone()
				newHair.Name = "FirstHair"
				newHair.Parent = dummy

				-- Create a new Weld between the newHair.Handle and the dummy's head
				local weld = Instance.new("Weld")
				weld.Name = "HeadWeld"
				weld.Parent = dummy.Head
				weld.Part0 = dummy.Head
				weld.Part1 = newHair.Handle
				local Position = newHair.AttachmentPoint.Position
				local Orientation = newHair.AttachmentPoint.Orientation
				weld.C1 = (CFrame.new(0, 5, 0) * CFrame.Angles(0, math.rad(Orientation.Y), 0))
				
			else
				print("Hair model not found:", slotValue)
			end
		end
	end
end
4 Likes

This is confusing because of how the data is displayed in the Properties panel. An Attachment instance has a CFrame property that you can set direct using a full CFrame. Additionally, it has “properties” of Position and Orientation, but I put this in quotes because they are not true properties, they are getter and setter functions for the underlying CFrame. You can set Attachment.Orientation to a Vector3 of Euler angles in degrees. These will internally update the Attachment’s CFrame. The resulting angle values you see in the properties panel may not stay the exact X, Y, and Z values you set, but the orientation will be equivalent.

The CFrame data structure itself is immutable; not changable once constructed, so you can’t set just the position or orientation part from Lua, you need to either use the set/get properties of the Attachment itself, or you need to manually construct the new full CFrame and set Attachment.CFrame.

1 Like

Sorry I am slightly confused at how to go about doing the first part, like as in setting it to a Vector3, It might be a simple thing and Im just dumb idk, but im kinda confused sorry!

1 Like

I managed to figure out a way to use something called “ToOrientation” (which I didnt even know existed) to get each individual Orientation value and I was able to fix it

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.