How i can change a parent of a attachment and keeping the position?

I’ve been facing this problem for a while now, and it would be great if it were possible to change the attachment’s parent while maintaining its position, this would save a lot of time because my game will use several attachments, does anyone know a way to do this?

yes you can make it with script from the command bar with the use of attachment.WorldPosition
i tried to make this as simple as i can

-- add ur attachments in this table and seperate them with ,
local attachments = {
	workspace.att1,
	workspace.att2,
}
local parent = workspace.tank -- replace to where u want ur attachments to move to

for _,i :Attachment in attachments do
	local worldCFrame = i.WorldCFrame -- saves the CFrame
	i.Parent = parent -- parents the attachment
	i.CFrame = worldCFrame -- apply the CFrame
end

this script will copy the attachment world CFrame aka (position and rotation) and save them and then parent them to the parent variable and apply the CFrame
i havnot tested this so amnot sure if it will work

if this script feels complicated you can try asking the studio ai to do it amnot sure if it will work but

1 Like

thank you so much it worked!

iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

1 Like

hi man, idk why but it dont work for every attachment, like these:

i edit your script to make that more eazy to use, idk if that maked stop working:

– add ur attachments in this table and seperate them with ,

local parent = workspace.tank.Hull.Attachments – replace to where u want ur attachments to move to

for _,i in pairs(game.Workspace:GetDescendants()) do
if i.Name == “HingeAttachment” then
local attach = i:Clone()

	local worldCFrame = attach.WorldCFrame -- saves the CFrame
	attach.Parent = parent -- parents the attachment
	attach.CFrame = worldCFrame -- apply the CFrame
end

end

1 Like

hi
idk exactly why itsnot working but i will say some things that may be the reason

things that may be the reason

make sure that attachments is an attachment or a block and not a folder

make sure that there name is HingeAttachment idk if there is smt called HingeAttachment did u mean “HingeConstraint”?

amnot sure of this but if it still didnot work then try changing it to
local worldCFrame = i.WorldCFrame

i mostly think that the reason is that some of them arnot not named “HingeAttachment” that may be why it worked for some and others not try adding a print(i) after the if statment to see how many attachment was printed

i only know about welds and attachments i haven’t tried the other stuff so idk how they work

and you donot have to use pairs just do game.Workspace:GetDescendants() since you donot have to get the key

1 Like

thanks for reply!

I did the things you recommended and it still didn’t work… but I realized that it doesn’t work because I clone the attachment, so I redid the code:

local parent = workspace.tank.Hull.Attachments

for _,i in pairs(game.Workspace:GetDescendants()) do
if i:IsA(“Attachment”) and i.Name == “HingeAttachment” then

	local clone = i:Clone()
	clone.Name = i.Parent.Parent.Name

	local worldCFrame = i.WorldCFrame


	clone.Parent = parent


	clone.WorldCFrame = worldCFrame
end

end

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.