How to fix my script that attaches a part to an attachment with orientation?

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix my script that I made to attach a part to an attachment with the same orientation.
    This is my script:
local floorCframe = RaycastInstance.CFrame * CFrame.new(attachment.Position)
local emptyVector = Vector3.new(0,0,0)
local attachmentWorldUpvector = attachment.SecondaryAxis
local attachmentWorldRightvector = attachment.Axis

local goalRotationCFrame = CFrame.fromMatrix(emptyVector,attachmentWorldRightvector,attachmentWorldUpvector)
floorCframe = floorCframe * goalRotationCFrame
floorCframe = floorCframe * CFrame.new(-Structure.FloorAttachment.Position)
Structure.CFrame = floorCframe

And this is what happens sometimes (It doesn’t work) :

And sometimes it works, (This is what I want it to always do) :

  1. What is the issue? Include screenshots / videos if possible!
    Sometimes It works and sometimes it doesn’t and I don’t know why.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried Devforum and YT

I took this script from this post : How to rotate part according to attachments orientation
I made it work to mine and it still doesn’t work sometimes. But in that post the guy uses mouse position, not raycasting and I am using raycasting. Idk if that has something to do with it. Please respond quickly as I need to get this done asap. Thank you for your time.

1 Like

If the guy in the video is using mouse position and it’s working then you should adapt your system to that

Well, i think that he is using mouse position and also I have made my script for raycasting and i dont feel like changing it to mouse position

But there has to be a problem, but i just cant figure it out

Im still confused on the issue, is it not snapping in the correct place? Just a still image cant really give people an idea of what the problem looks like

it snaps properly but the orientation of it is messed up for some reason.

So its not rotated the right way? Then how about try rotating it after it is placed?

1 Like

I cant, i want it to rotate in the placing stage, but also it should work, but it just doesnt some times. There has to be an error somewhere because it cant just work sometimes and others not.

Okay lets just take a look at that code then, the part that is doing this

im not sure which part is doing that :confused:

Well if I had to guess its somewhere in your script where your handling placing a foundation?

yea, but all i know is that it is in the script that i have provided here

Could you send a video of the problem happening because the still images just arent helping