Move part with the position of another part in raycast

take a look the the video

yes, is self-explainable i think. i want to make the white part follows the tree log position in every angle except Y axis

on a local script somewhere?

game['Run Service'].RenderStepped:Connect(function()
local y = log.Position.Y

log.CFrame = wood.CFrame
log.Position = Vector3.new(wood.Position.X, y, wood.Position.Z)
end)

if that is what you mean i’m not really sure

sorry if I can’t explain it well, so I want the rectangle to move to follow the position of the cylinder with the offset of the mouse


local mouse = game.Players.LocalPlayer:GetMouse()
local camera = workspace.CurrentCamera
local cylinder = --where ever the cylinder is
local rectangle = --where ever the rectangle is

game['Run Service'].RenderStepped:Connect(function()
local direction = camera:ScreenPointToRay(mouse.X, mouse.Y).Direction*100
local cast = workspace:Raycast(camera.CFrame.Position, direction)

if cast.Instance == cylinder then

local additional = 0

additional = cast.Position.Z-cylinder.Position.Z

rectangle.CFrame = cylinder.CFrame*CFrame.Angles(0,math.rad(90), 0)
*CFrame.new(0,0,-cylinder.Size.X/2)*CFrame.new(0,0,additional)

end

end)

try fiddling around with that and see what happens?

thanks for your help, ima test it

nope still not working as intended :frowning:

cheers mate for that insightful reply, could you explain what isn’t working + screenshots

okay, i will send the screenshot and try my best to explain


i want to make the middle/grey part go like shown in the video, what i got from your code is like this