Parts are freezing on client side

So I am working on a destruction system and it seems to work pretty well on server side. But when I test the game on client, the structure starts freezing mid air even though there are no frame drops.

I have tried setting the network owner to all of the parts in the structure to nil but it doesn’t seem to change much.

When falling, the whole structure is set to CanCollide = false. On impact the bigger parts are replaced with smaller peaces and welded together using :JoinToOutsiders() and the chunks that are colliding with the ground are Destroyed.

Server side:

Client side:

Looks like an issue where the parts network ownership is being set to the nearest client. When that happens (ownership change) there is a little lag spike. To prevent this, set the network owner to the server by passing nil as the parameter. basePart:SetNetworkOwner(nil). This will prevent the assembly from automatically being set to the nearest client

documentation:
https://create.roblox.com/docs/reference/engine/classes/BasePart#SetNetworkOwner

I’ve tried it already. Pretty sure it’s not the issue here.

Well, I believe it’s a jittering with replication. Could you tell me flow of this? Creating, when does it start to fall and what properties do you set

Here is the code that replaces the bigger parts in the structure with smaller fragments:

function replacePartWithFragments(originalPart, fragmentSize, gap)
	gap = 0

	
	local originalCFrame = originalPart.CFrame
	local originalSize = originalPart.Size
	local originalParent = originalPart.Parent

	
	local xCount = math.ceil(originalSize.X / fragmentSize.X)
	local yCount = math.ceil(originalSize.Y / fragmentSize.Y)
	local zCount = math.ceil(originalSize.Z / fragmentSize.Z)

	
	local actualFragmentSize = Vector3.new(
		originalSize.X / xCount,
		originalSize.Y / yCount,
		originalSize.Z / zCount
	)

	
	local fragmentSizeWithGaps = actualFragmentSize - Vector3.new(gap, gap, gap)


	local fragments = {}

	-- Create fragments
	for x = 0, xCount - 1 do
		for y = 0, yCount - 1 do
			for z = 0, zCount - 1 do
				
				local offset = Vector3.new(
					(x * actualFragmentSize.X) - (originalSize.X / 2) + (actualFragmentSize.X / 2),
					(y * actualFragmentSize.Y) - (originalSize.Y / 2) + (actualFragmentSize.Y / 2),
					(z * actualFragmentSize.Z) - (originalSize.Z / 2) + (actualFragmentSize.Z / 2)
				)

				-- Create fragment
				local fragment = Instance.new("Part")
				
				fragment.Size = fragmentSizeWithGaps
				fragment.CFrame = originalCFrame * CFrame.new(offset)
			
				fragment.CanCollide = false
				fragment.Parent = originalParent
				fragment.AssemblyLinearVelocity=originalPart.AssemblyLinearVelocity

				-- Copy all visual properties
				fragment.Material = originalPart.Material
				fragment.Color = originalPart.Color
				fragment.Transparency = originalPart.Transparency
				fragment.Reflectance = originalPart.Reflectance

				

				table.insert(fragments, fragment)
			end
		end
	end
	
	
	originalPart:Destroy()
	for i,v in pairs(fragments) do
		
		
		workspace:JoinToOutsiders({v}, Enum.JointCreationMode.Surface)
		
		
	end
	return fragments
end

Could you show the code where you’re setting the network owner to nil?

Sure! here is the other part of the code:

game:GetService("RunService").Heartbeat:Connect(function()
	for i,part in pairs(workspace.Debri:GetDescendants()) do
		if part:IsA("BasePart") and part:IsGrounded()==false then
			part:SetNetworkOwner(nil)

			if part.AssemblyLinearVelocity.Magnitude>=impspeed then
				
				local touchingparts = workspace:GetPartsInPart(part)
				if #touchingparts~=0 then
					local validcollision
					for i,v in pairs(touchingparts) do
						if (v.AssemblyLinearVelocity-part.AssemblyLinearVelocity).Magnitude>=impspeed then
							validcollision=true
							if v:IsDescendantOf(workspace.Debri) then
								if v.Size.X>fragmentSize or v.Size.Y>fragmentSize or v.Size.Z>fragmentSize then
									replacePartWithFragments(v,Vector3.new(fragmentSize,fragmentSize,fragmentSize))
									else
								game.Debris:AddItem(v,0.05)
								end
							end
						end
					end
					if validcollision then
					
					if part.Size.X>fragmentSize or part.Size.Y>fragmentSize or part.Size.Z>fragmentSize then
						replacePartWithFragments(part,Vector3.new(fragmentSize,fragmentSize,fragmentSize))
					else
						local totalmass = 0
							for i,v in pairs(part:GetConnectedParts(false)) do
								totalmass+=v.Mass
							end
							
						
							part:ApplyImpulseAtPosition(part.AssemblyLinearVelocity.Unit*-math.min(150*(1/(0.01*#part:GetConnectedParts(true)))*part.Mass,totalmass*part.AssemblyLinearVelocity.Magnitude), part.Position)
					part.AssemblyAngularVelocity/=1.2
						
						part:Destroy()
					end
					end
					end
				part.CanCollide=false
			else
				part.CanCollide=true
			end



		end
	end 
end)