Why aren't the parts returning to where they're supposed to go?

When I press the separate button, it doesn’t return them where they’re supposed to go. Every other button (union) it returns the parts to their spots just fine. I think I’ve tried just about every combination of cframe inverses there is.

Some things to look out for: There is a ExtentsCFrame that is the actual center of the part, of which I use. I can’t decide if it’s a good idea to use it or not. Other than that, good luck, I’ve spent about 3 hours on this today :confused:

1 Like

Could you please paste in your code? (You can use a code block for syntax highlighting)

I know you sent the file but I would appreciate just the relevant code if possible. Thanks!

1 Like

Well there’s only one script, but sure, here’s the code that separates. Do you also need the code that saves the parts’ positions? I’ll include that too :D

Separate button code:

local function RejuvenateChildren(part)
	
	for _, child:BasePart in part:GetChildren() do

		child.Parent = part.Parent
		
		child.CFrame = part.ExtentsCFrame * child.ExtentsCFrame:Inverse()

		local splitString = string.split(child.Name,"_")
		child.Transparency = splitString[1]
		child.CanCollide = splitString[2]
		child.Anchored = splitString[3]
		child.Name = splitString[4]
		child.CanQuery = true
		
		addHighlight(child)

	end

	part:Destroy()
	
end

Separate.MouseButton1Click:Connect(function()
	
	ContextActionService:UnbindAction("clickToSelectMainPart")
	
	if mainPart == nil then
		warn("You Need To Select A Main Part")
		return
	end
	
	local otherParts = GetOtherParts() -- returns an array of any other parts that were selected (they have a blue outline)
	
	RejuvenateChildren(mainPart)
	
	for _, otherPart in pairs(otherParts) do
		RejuvenateChildren(otherPart)
	end
	
	CleanUp()
	
end)

And the code that saves the parts’ positions:

local function cloneParts(partToClone, parent) -- transparency_cancollide_anchored
	
	local clone:BasePart = partToClone:Clone()
	clone.Name = tostring(partToClone.Transparency) .. "_" .. tostring(partToClone.CanCollide) .. "_" .. tostring(partToClone.Anchored) .. "_" .. partToClone.Name
	clone.Transparency = 0.75
	clone.Anchored = true
	clone.CanCollide = false
	clone.CanQuery = false	
	clone.CFrame = partToClone.ExtentsCFrame:ToObjectSpace(parent.ExtentsCFrame)
	clone.Parent = parent
	
end

local function NewPartsFinishingTouches(newParts, otherParts)
	
	ContextActionService:UnbindAction("clickToSelectMainPart")
	
	for _, newPart in pairs(newParts) do

		newPart.Anchored = true
		newPart.Parent = mainPart.Parent

		cloneParts(mainPart, newPart)

		for _, otherPart in pairs(otherParts) do			
			cloneParts(otherPart, newPart)
		end

		addHighlight(newPart)

	end

	mainPart:Destroy()
	mainPart = nil

	for _, otherPart in pairs(otherParts) do
		otherPart:Destroy()
	end
	
	CleanUp()
	
end

Intersect.MouseButton1Click:Connect(function()

	local otherParts = GetOtherParts()
	
	local success, newParts = pcall(function()
		return GeometryService:IntersectAsync(mainPart, otherParts, {SplitApart = true})
	end)

	if success and newParts then
		NewPartsFinishingTouches(newParts, otherParts)
	end
	
end)

Thanks!

1 Like

Considering this statement.
Off the top of my head. Part handle comes to mind.
If you want something to go back to were it was. No matter the handle spot.
Save where it was to start with… then just move it back to that save variable.
This skips all the math and will always be right.

1 Like

I need it to return relative to where the remaining part is:

So I need to remember where it is relative to the new intersected part, therefore the need for math :c

I’m just going to stick with my guess here…
With nothing to really work with I’d just be as was speculating.

No worries :hugs:

30 chаr
2 Likes

Replace all the ExtentsCFrame’s with just CFrame’s… Such a simple solution :man_facepalming:

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