Needing to change the position & orientation of a motor6d's part1

Hi. I recently just found out how to make a weapon attachments system, which I’m currently porting to my gun kit. linked here: Tips for making a weapon modification system - #2 by PostVivic and I want to now Motor6D the attachment (which is a suppressor) to the tool’s handle (which in this case is “BodyAttach”) I have Motor6D’d it successfully, but my issue is I’m not sure how to change the orientation & position.

I have tried to code the suppressor’s orientation changing, it’s variable is attachment1.

attachment1 = attachment:Clone()
print(attachment1)
attachment1.Parent = Tool
attachment1.CFrame = (MuzzleModPoint.WorldCFrame attachment1.AttachmentPoint.CFrame:Inverse())
orientation = attachment1.Orientation – gets the original orientation pre motor6d
m6d = Instance.new(“Motor6D”, Handle)
m6d.Part0 = Handle
m6d.Part1 = attachment1
attachment1.Orientation = orientation

However this doesn’t work. I haven’t attempted to change the position either though.

This is my second devforum post request thing, so I’m sorry if I don’t elaborate enough :grinning:

Hello I was summoned because you linked my post :stuck_out_tongue: Motor6ds will keep the parts in a fixed position set with C0 and C1, I used a WeldConstraint because it doesn’t have that limitation, I forgot to specify that in my post, just change this line

m6d = Instance.new("Motor6D", Handle)

to

m6d = Instance.new("WeldConstraint", Handle)
1 Like

Thank you! Oh hahah I never realised it tells people when their post is linked

Thank you again :grin:

Just a side note, for formatting code you want 3 backticks (```) at the top and bottom, and it’s best to keep a consistent naming scheme (camelCase or PascalCase are the most common). It’s also best to set the parent separately to creating the instance (don’t use the second argument of Instance.new()) since Roblox starts listening to changes and updating stuff when an object has a parent, so your code will be less efficient. You will also be better off using local variables as well (just stick local in front of the variable when you first assign a value to it). Your code for creating the weld would then become:

local Weld = Instance.new("WeldConstraint")
Weld.Part0 = Handle
Weld.Part1 = Attachment1
Weld.Parent = Handle
1 Like

Thank you for the advice, I’ll be sure to start doing this. I never realised that parenting the object in the second argument of Instance.new caused efficiency issues! Thank you though

The reason why is if you parent an instanced object to a directory which replicates to each client then proceeding property changes will also need to replicate one by one, by setting all of the properties of an instanced object first before setting its parent property when the object is eventually parented to a directory which replicates the object and all of its properties will replicate to each client all at once.

2 Likes