Random error on simple code

I have a simple optimization script, that makes every part with a material in the game become Plastic.

The code DOESN’T work, and it errors:

The current thread cannot access ‘StreamingService’ (lacking capability Assistant) - Client

I have found no solution for this error so far. I hope someone can help me.

For anyone wondering, this is the code

local TimesClicked = 1
script.Parent.MouseButton1Click:Connect(function(Optimize)

		if TimesClicked== 1 then
			local TableForPreviousMaterials = {}

		
			for i, children in pairs(game:GetDescendants())do
									if children.ClassName == "MeshPart" or children.ClassName == "BasePart" or children.ClassName == "UnionOperation" then
						TableForPreviousMaterials [children] = children.Material
					end
				end
		
			function UndoOptimization(material)
				for part, StoredMaterial in pairs(TableForPreviousMaterials) do		
					part.Material = material or StoredMaterial
				end
			end
			UndoOptimization(Enum.Material.Plastic)
			TimesClicked= 2
		if TimesClicked== 2 then
			UndoOptimization(nil)
			TimesClicked= 1
		end
		end
end)



7 Likes

what line is the errorrrr on?

also click this “format document”

2 Likes

Ninth line, it says.

COULD YOU FORMAT? I DID IT BY HAND :skull:

local numero = 1
script.Parent.MouseButton1Click:Connect(function(goofy)

	if numero == 1 then
		local materials = {}


		for i, children in pairs(game:GetDescendants())do
			if children.ClassName == "MeshPart" or children.ClassName == "BasePart" or children.ClassName == "UnionOperation" then
				materials[children] = children.Material
			end
		end

		function UndoOptimization(material)
			for part, savedMaterial in pairs(materials) do		
				part.Material = material or savedMaterial
			end
		end
		UndoOptimization(Enum.Material.Plastic)
		numero = 2
		if numero == 2 then
			UndoOptimization(nil)
			numero = 1
		end
	end
end)


2 Likes

You should be doing

game.Workspace:GetDescendants()

Full:

local numero = 1
script.Parent.MouseButton1Click:Connect(function(goofy)

	if numero == 1 then
		local materials = {}


		for i, children in pairs(game.Workspace:GetDescendants())do
			if children.ClassName == "MeshPart" or children.ClassName == "BasePart" or children.ClassName == "UnionOperation" then
				materials[children] = children.Material
			end
		end

		function UndoOptimization(material)
			for part, savedMaterial in pairs(materials) do		
				part.Material = material or savedMaterial
			end
		end
		UndoOptimization(Enum.Material.Plastic)
		numero = 2
		if numero == 2 then
			UndoOptimization(nil)
			numero = 1
		end
	end
end)
5 Likes

change that to this aswell, also do what the other guy says

if children:IsA("BasePart") then
	TableForPreviousMaterials [children] = children.Material
end
4 Likes

I feel this error is connected to ROBLOX’s script capabilities preview.

Do you have Script Capabilities enabled in your Beta Features? If you do, then disable it.

1 Like

No, I don’t have it enabled. Since the error mentions Assistant, I think it’s that. (no #### sherlock)

1 Like

I hope this helps, try using a pcall.

@lostresosostedyIII

3 Likes

Thank you!

2 Likes

did it work? I really hope it did, good luck!!!

2 Likes

It did!

3 Likes

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