Issues with :UnionAsync

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I would like to figure out what causes :UnionAsync to freeze my code in this scenario and fix the issue.

  1. What is the issue? Include screenshots / videos if possible!

:UnionAsync does not seem to work, there are no errors returned and it seems to freeze my code making “Test2” not print.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried asking chatgpt, who advised me to unpack the variable “OtherMatrixLines” in the :UnionAsync but that gave an error.
I have also tried reducing “MatrixWidth” to 6 to see if it is the amount of parts, which does not seem to be the issue.
I tried looking for “:UnionAsync not working” and similar phrases on google and the dev forum and have found barely any, and they do not seem to apply to my case.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I don’t know how to best give an example without showing all my code so…

There is a RemoteEvent called CreateMatrixGridEvent in ReplicatedStorage.

type: LocalScript, Position: StarterPlayerScripts

local MatrixWidth = 35
local MatrixHeight = MatrixWidth * 2
local PrepDistance = 1
local MatrixLineAmount = MatrixWidth - PrepDistance
local MatrixClimb = "placeholder"

local Matrix = Instance.new("Folder")
Matrix.Parent = game.Workspace
Matrix.Name = "Matrix"

local MatrixLineSpaces = MatrixLineAmount - 1
local MatrixLineDistance = (MatrixWidth - PrepDistance * 2) / (MatrixLineSpaces)
local MatrixLineAmountY = math.floor((MatrixHeight - PrepDistance * 2) / MatrixLineDistance)
local PrepDistanceY = (MatrixHeight - (MatrixLineAmountY * MatrixLineDistance)) / 2
local HalfWidth = MatrixWidth / 2
local HalfHeight = MatrixHeight / 2
local Vector3SizeX = Vector3.new(0, MatrixHeight, MatrixWidth)
local Vector3SizeY = Vector3.new(MatrixWidth, 0, MatrixWidth)
local Vector3SizeZ = Vector3.new(MatrixWidth, MatrixHeight, 0)

local PartDataString = ""
for I = 0, MatrixLineSpaces do
	
	PartDataString = PartDataString..tostring(Vector3.new(PrepDistance + I * MatrixLineDistance - HalfWidth, 0, 0))..";"..tostring(Vector3SizeX).."│"
	PartDataString = PartDataString..tostring(Vector3.new(0, 0, PrepDistance + I * MatrixLineDistance - HalfWidth))..";"..tostring(Vector3SizeZ).."│"
end
for I = 0, MatrixLineAmountY do
	
	PartDataString = PartDataString..tostring(Vector3.new(0, PrepDistanceY + I * MatrixLineDistance - HalfHeight, 0))..";"..tostring(Vector3SizeY).."│"
end

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CreateMatrixGrid = ReplicatedStorage:WaitForChild("CreateMatrixGridEvent")
CreateMatrixGrid:FireServer(PartDataString)

type: ServerScript, Position: ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CreateMatrixGrid = ReplicatedStorage:WaitForChild("CreateMatrixGridEvent")

CreateMatrixGrid.OnServerEvent:Connect(function(Player, PartDataString)
	
	local TempFolder = Instance.new("Folder")
	TempFolder.Parent = game.Workspace
	TempFolder.Name = "TempFolder"
	
	for I, V in string.split(PartDataString, "│") do
		
		if V ~= "" then
			
			local MatrixLineData = {}
			for StoredData in string.gmatch(V, "[^;,]+") do
				
				table.insert(MatrixLineData, StoredData)
			end
			local MatrixLine = Instance.new("Part")
			MatrixLine.Anchored = true
			MatrixLine.Transparency = 0
			MatrixLine.Position = Vector3.new(tonumber(MatrixLineData[1]), tonumber(MatrixLineData[2]), tonumber(MatrixLineData[3]))
			MatrixLine.Size = Vector3.new(tonumber(MatrixLineData[4]), tonumber(MatrixLineData[5]), tonumber(MatrixLineData[6]))
			MatrixLine.Parent = TempFolder
		end
	end
	
	local FirstMatrixLine = TempFolder:GetChildren()[1]
	local OtherMatrixLines = TempFolder:GetChildren()
	table.remove(OtherMatrixLines, 1)

	print("Test1")
	
	local success, MatrixGrid = pcall(function()
		return FirstMatrixLine:UnionAsync(OtherMatrixLines)
	end)
	
	if success then
		print("Union succeeded.")
	else
		print("Error in union: " .. MatrixGrid)
	end
	print("Test2")
end)

Here is an image of what it Currently does :

image

What i would like for it to do is convert the “block” into a union

This is my first forum Post too, so i hope this was clear on what i wish to achieve, my issues, and what i have tried

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Not entirely sure how you got those part lines, but Roblox’s union service doesn’t work with all part types. Only a small select of part types, excluding meshes, are accepted which could be the reason your code is struggling.

If they are parts, then try unionizing smaller clumps of parts, then unionize the smaller clumps into the larger one.

I seem to have found the issue.

It instead of stopping the code, slowed it down a lot making it seem as if it had stopped, there was no error code because it took so long to do the union, after experimenting and waiting a lot it seemed to give error code -14 which means that its too complex.

a possible reason as to why even with lower numbers it didn’t union before restarting my computer is due to it still being overloaded with the last requested union somehow.

a possible workaround to this could be that instead of union-ing everything at the same time is to union everything in steps of around 25

Yeah I had a feeling it was that too, even when making unions of 20 parts it takes my computer a bit, I can only imagine how much it would take to do an entire grid. Glad you found the solution!

1 Like

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