I really need help with attachment generation

So I have a script that creates a bunch of attachments, but the thing is there will always be two attachments directly within each other, so basically double. I really need to delete the extra attachment.
I need to detect if there is an attachment inside another attachment

local item = Instance:GetChildren() -- Gets Instances within Instance

for index, object in item do -- Iterate through the Array of Instances
    if item:IsA("Attachment") then -- if the Item is an Attachment
        local att = object:FindFirstChildOfClass("Attachment") -- Searches for Attachment based on class
        if att then -- if FindFirstChildOfClass returned an Attachment
            att:Destroy() -- Destroy the Attachment

That unfortunately isn’t going to work. There are hundreds of attachments stored into one part, and all of them of which have one unnecessary attachment directly inside of it.

I’d recommend replacing that with a dash “_” if you’re not using it to save some memories. Just a recommendation :sweat_smile:

Doesnt really matter, all _ does is to throw away something, plus can be useful.

This is what I’m trying to do. The little block is the part with the attachments. All of the little green dots you see are attachments, and there are two attachments per green dot. I only need one per dot.

Quick question however, why and how are you creating two attachments per Object?

Well, actually nvm its actually up to five (or 100) attachments in one spot. I used a plugin to convert a meshpart into triangles, then I am getting the points of every triangle, and creating an attachment. The bad thing is that there could be an unlimited number of attachments depending on how many triangles meet on one spot. I am creating triangles at every vertex.

I did a test and I found a vertex where there is 6 attachments in the same spot lmao

You could detect it using the position of each attachment? (I’m not a coder so idk how you would go about doing this but I feel like this would be the easiest solution)

That’s what I’m doing. The problem that I have is that all of the attachments are comparing each other, so they all destroy each other.

So maybe get the attachment WorldPosition/WorldCFrame instead?

That’s what I always use. And another thing is that the normal position would still work because they’re all in the same spot.

for i,v1 in pairs(workspace.AttaPart:GetChildren()) do
	for i,v2 in pairs(workspace.AttaPart:GetChildren()) do
		if (v1.WorldPosition-v2.WorldPosition).Magnitude < 0.01 then

This is what I have so far. All of the attachments destroy each other, because for some reason even the destroyed attachments still compare the other ones.

So you want attachments that are too close or in the exact spot from one of another deleted, right?

Precisely. 3030303003030303bruh

Could you explain what do you mean by destroyed attachments still compare the other one?

So the first for loop loops through all of the attachments, but some how it still counts deleted attachments as existing. What I mean is the deleted attachments compare the distance to existing attachments, and if its too low then it deletes them.

Wait nvm lmao I fixed it by checking if the v1 was v2. I just need to re-connect the triangles with the attachments.

1 Like

@SageToxigen Thanks for helping me realize basic logic, and therefore I have created my own skinned guy.

1 Like

You’re welcome! Don’t forget to mark it solved so people knows that you already found a solution. :heart:

1 Like