How to locally turn on and off textures?

I have a settings menu in my game that has different settings for the player to turn on and off to their preferences.


I want to have a setting that allows you to turn on and off materials/textures (or just set all of them to plastic). How could I got about doing this from a local script? if anyone can help I would appreciate it!

4 Likes

you could run a for loop for every single part / texture in the workspace.

Example:

for i,v in game.workspace:getdescendants() do
if v:IsA(“BasePart”) then v.Material = enum.Material.Plastic end end
end

You can make the for loop check for the texture instances and surface appearances to remove / disable them

Do you know how I could set them back to the material they were before? when the button is pressed back

1 Like

You could do something where the server sends the textures to the client so the client can replicate it. Or you could find a way to save the textures of every part in the background like in a script or via attributes. But I think the first option is probably the easiest

1 Like

This should work:

local button = script.Parent
local materialsVisible = true

function hideMaterials(gameParts)
	local oldMaterial = Instance.new("StringValue")
	oldMaterial.Value = gameParts.Material.Name
	oldMaterial.Name = "OldMaterial"
	oldMaterial.Parent = gameParts

	gameParts.Material = Enum.Material.SmoothPlastic
end

function showMaterials(gameParts)
	local oldMaterial = gameParts:FindFirstChild("OldMaterial")
	gameParts.Material = Enum.Material[oldMaterial.Value]
	oldMaterial:Destroy()
end

button.MouseButton1Click:Connect(function()
	if materialsVisible == true then
		materialsVisible = false

		for i, gameParts in pairs(workspace:GetDescendants()) do
			if gameParts:IsA("BasePart") then
				hideMaterials(gameParts)
			end
		end
	else
		materialsVisible = true

		for i, gameParts in pairs(workspace:GetDescendants()) do
			if gameParts:IsA("BasePart") then
				showMaterials(gameParts)
			end
		end
	end
end)

3 Likes

Make a table to store all the previous materials, or set an attribute to save the material, then it can be restored.

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