How can I rotate a part in a certain way

I’m making a simple hovering script using raycasting, but I don’t know how to rotate the part 90 degrees like this. The part has an attachment that it puts at the raycasts position and normal. The part is teleported to the attachment’s lookvector * 5, but for some reason it’s rotated 90 degrees. The part is supposed to be parallel to the baseplate.
Screenshot (648)

atta.WorldCFrame = CFrame.new(pos, pos+norm)
part.CFrame = atta.WorldCFrame + atta.WorldCFrame.LookVector * 5

Why are you using an attachment? Especially inside the part. When changing the CFrame of the part the attachment will move along with it, is this your intended behavior?

I would just make a variable to store the variable, thus making a non-physical point which you can alter and use:

local point = CFrame.new(pos, pos+norm)
part.CFrame = point.CFrame + point.CFrame.LookVector * 5

My end goal is to make the part hover above any surface, and it also aligning itself with it, like this.


This is my code so far: (it still snaps 90 degrees for some reason)

local part = script.Parent
local atta = part.Attachment
local tweenService = game:GetService("TweenService")
local gotweeninfo = TweenInfo.new(0.5,Enum.EasingStyle.Quart,Enum.EasingDirection.Out,0,false,0)
--part.Velocity = part.CFrame.UpVector * 5
game:GetService("RunService").Heartbeat:Connect(function()
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {script.Parent}
	params.FilterType = Enum.RaycastFilterType.Blacklist
	local ray = workspace:Raycast(part.Position, part.CFrame.LookVector * 25, params)
	if ray then
		local pos = ray.Position
		local dist = ray.Distance
		local norm = ray.Normal
		local inst = ray.Instance
		local mat = ray.Material
		atta.WorldCFrame = CFrame.new(pos, pos+norm)
		tweenService:Create(part,gotweeninfo,{Position = (atta.WorldPosition + atta.WorldCFrame.LookVector * 5)}):Play()
		part.Orientation = Vector3.new(-90,0,0)
		--part.CFrame = CFrame.new(atta.WorldPosition + atta.WorldCFrame.LookVector * 5,pos+norm)  
		--part.Position = pos + atta.WorldCFrame.LookVector * 5
		--part.Velocity = Vector3.new(part.Velocity.X,0,part.Velocity.Z)
		--local part1 = Instance.new("Part")
		--part1.Anchored = true
		--part1.Parent = workspace
		--part1.CFrame = CFrame.new(atta.WorldPosition + atta.WorldCFrame.LookVector * 5)
	end
end)


I kina got it to work, but it snaps at weird angles on the y axis.

sorry the video is so short it was like 30 mb for some reason even though it was just like a 20 second clip