Found a strange something in part orientation

Hi! i have a trouble…
When i try to change part orientation, his Y position makes higher, idk whats wrong but idk how to fix that too.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
	wait(1.5)
local TweenService = game:GetService("TweenService")
local function TweenInformation(timing, Style, Direction)
	local CurrentInformation = TweenInfo.new(tonumber(timing), Enum.EasingStyle[Style], Enum.EasingDirection[Direction], 0, false, 0)
	return CurrentInformation
end
		local petpart = workspace:FindFirstChild("petpart")
while true do
			wait(.2)
			if (character.HumanoidRootPart.Position-petpart.Position).Magnitude >= 10 then
				local zcoo = character.HumanoidRootPart.Position.Z - petpart.Position.Z
				local xcoo = character.HumanoidRootPart.Position.X - petpart.Position.X
				if zcoo > 1.5 then zcoo = 1.5 elseif zcoo < -1.5 then zcoo = -1.5 end
				if xcoo > 1.5 then xcoo = 1.5 elseif xcoo < -1.5 then xcoo = -1.5 end
				local start = petpart.CFrame+Vector3.new(xcoo*2,17.5,zcoo*2)
				local lookAt = (start * CFrame.new(0,-5,0)).p
				local ray = Ray.new(start.p, (lookAt-start.p).Unit * 100)
				local part, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, {character, petpart, petpart})
				TweenService:Create(petpart, TweenInformation(0.1, "Sine", "Out"), { Position = Vector3.new(petpart.Position.X+xcoo, petpart.Position.Y+petpart.Size.Y*1.35, petpart.Position.Z+zcoo)}):Play()
				wait(.15)
				TweenService:Create(petpart, TweenInformation(0.1, "Sine", "Out"),{  Position =  Vector3.new(petpart.Position.X+xcoo, position.Y+petpart.Size.Y/2, petpart.Position.Z+zcoo), Orientation = part.Orientation}):Play()
				else
			end
		end
	end)
end)
1 Like

hmm, maybe if you’re in studio and the block is in “anchored” it wouldn’t move(sometimes)
basically when im in studio I “anchored” the block and it moves very differently than what I need it to move. Maybe try un-achoring it but keep it grouped to see if the position of it changes, then “anchored” it back. (50/50 chance it would work)

that’s not work (( i will try more

1 Like

ok, good luck with that situation then✔

Hey

BasePart.Position and BasePart.Orientation are properties you should only read from, never set (except in very weird specific occasions but i’ve never had any in over 4 years)

You should use BasePart.CFrame instead. It basically serves as both position and orientation.

Here’s a basic CFrame constructor: CFrame.new(position) * CFrame.Angles(0,0,0)
Here’s the same constructor except with specific position and orientation: CFrame.new(10,5,2) * CFrame.Angles(math.rad(90),math.rad(5),math.rad(10))

The first numbers in “CFrame.new()” is the vector3 position, so basically same as the BasePart.Position you’d want to set, and “CFrame.Angles()” is the orientation, HOWEVER - you have to convert each degree number with math.rad(). So for example, instead of typing CFrame.Angles(90,0,0) you type in CFrame.Angles(math.rad(90),0,0) to rotate it by 90 degrees on the X axis

1 Like

how can i get orientation from CFrame? i tried …CFrame[numberofpos], and that not work

local X,Y,Z = CFrame:ToOrientation()

or alternatively you can use
local X,Y,Z = CFrame:ToEulerAnglesYXZ()
(if i recall correctly for some reason you have to use ToEulerAnglesYXZ instead of ToEulerAnglesXYZ, but if it’s wrong then use ToEulerAnglesXYZ, but ToOrientation always does the job so just use it)

1 Like