Need help disabling certain materials in my game

Hello, I am looking to make a material disabler in my game so that lower end systems are still able to run the experience. However, I don’t want it to disable forcefields, how would I do this?

(Current script for disabling materials below.)

local SettingsKey = Enum.KeyCode.M

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Frame = script.Parent
local Shader = Frame.Shader
local Materials = Frame.Materials
local CustomCursor = Frame.CustomCursor
local KillSound = Frame.WeaponKillSound
local DamageNumberSize = Frame.DamageNumberSize
local HitSound = Frame.HitSound
local WeaponSounds = Frame.WeaponSounds
local DamageNumbers = Frame.DamageNumbers
local HitMarker = Frame.HitMarker
local UIS = game:GetService("UserInputService")
local Lighting = game:GetService("Lighting")
local SmoothPlastic = Enum.Material.SmoothPlastic
local objects = {}
local IsOpen = false
local ShaderEnabled = true
local MatEnabled = true
local WeaponSoundsEnabled = true
local HitSoundEnabled = true
local DamageNumbersEnabled = true
local KillSoundEnabled = true
local HitMarkerEnabled = true
local function Scan(Object)
	local objectlist = Object:GetChildren()
	for i = 1, #objectlist do
		if objectlist[i]:IsA('BasePart') then
			objects[objectlist[i]] = objectlist[i].Material
		end
		Scan(objectlist[i])
	end
end

Scan(workspace)

function MakeButton(Button,On)
	if On then
		Button.Label.Text = "ON"
		Button.Label.TextColor3 = Color3.fromRGB(0,255,0)
	elseif not On then
		Button.Label.Text = "OFF"
		Button.Label.TextColor3 = Color3.fromRGB(255,0,0)
	end
end
Materials.MouseButton1Click:Connect(function()
	if MatEnabled then
		MatEnabled = false
		MakeButton(Materials,MatEnabled)
		
		for i in pairs(objects) do
			i.Material = SmoothPlastic
		end
		
	elseif not MatEnabled then 
		MatEnabled = true
		MakeButton(Materials,MatEnabled)
		
		for i in pairs(objects) do
			i.Material = objects[i]
		end
		
	end
end)

“Disable” is not something that you can do. When other games “disable” materials, they are actually removing textures from the parts and, or, setting the parts’ Material property to SmoothPlastic.

To answer this,

“I don’t want it to disable forcefields,”

you’d just check if the part’s Material is set to ForceField, and then skip that part if so.

2 Likes

Here a simple script to do the job for you

local SmoothPlastic = Enum.Material.SmoothPlastic
local IgnoreMaterial = Enum.Material.ForceField

function Performance(Object:Instance)
	for i,v in pairs(Object:GetChildren()) do
		if v:IsA("BasePart") and v.Material ~= IgnoreMaterial  then
			v:SetAttribute("OldMaterial",v.Material.Value)
			v.Material = SmoothPlastic
		end
	end
end

function Stop_Performance(Object:Instance)
	for i,v in pairs(Object:GetChildren()) do
		if v:IsA("BasePart") then
		local OldMaterial =	v:GetAttribute("OldMaterial")
			if OldMaterial ~= nil then
				v.Material = OldMaterial
			else
				--Print(v.Name,"Didn't have performance")
				end
		end
	end
end
2 Likes

Thank you, I’m not too much of a scripter, this really helps!

Though can you tell me where I would put this to make it work?

suggesting local script to be a local but if you mean by the script you gave then i would suggest making it like this

local SettingsKey = Enum.KeyCode.M

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Frame = script.Parent
local Shader = Frame.Shader
local Materials = Frame.Materials
local CustomCursor = Frame.CustomCursor
local KillSound = Frame.WeaponKillSound
local DamageNumberSize = Frame.DamageNumberSize
local HitSound = Frame.HitSound
local WeaponSounds = Frame.WeaponSounds
local DamageNumbers = Frame.DamageNumbers
local HitMarker = Frame.HitMarker
local UIS = game:GetService("UserInputService")
local Lighting = game:GetService("Lighting")
local SmoothPlastic = Enum.Material.SmoothPlastic
local IgnoreMaterial = Enum.Material.ForceField
local objects = {}
local IsOpen = false
local ShaderEnabled = true
local MatEnabled = true
local WeaponSoundsEnabled = true
local HitSoundEnabled = true
local DamageNumbersEnabled = true
local KillSoundEnabled = true
local HitMarkerEnabled = true

function Performance(Object:Instance)
	for i,v in pairs(Object:GetChildren()) do
		if v:IsA("BasePart") and v.Material ~= IgnoreMaterial  then
			v:SetAttribute("OldMaterial",v.Material.Value)
			v.Material = SmoothPlastic
		end
	end
end

function Stop_Performance(Object:Instance)
	for i,v in pairs(Object:GetChildren()) do
		if v:IsA("BasePart") then
		local OldMaterial =	v:GetAttribute("OldMaterial")
			if OldMaterial ~= nil then
				v.Material = OldMaterial
			else
				--Print(v.Name,"Didn't have performance")
				end
		end
	end
end

function MakeButton(Button,On)
	if On then
		Button.Label.Text = "ON"
		Button.Label.TextColor3 = Color3.fromRGB(0,255,0)
	elseif not On then
		Button.Label.Text = "OFF"
		Button.Label.TextColor3 = Color3.fromRGB(255,0,0)
	end
end
Materials.MouseButton1Click:Connect(function()
if MatEnabled then
		MatEnabled = false
	    Performance(workspace)
	elseif not MatEnabled then 
             MatEnabled = true
		Stop_Performance(workspace)
	end
end)

Thanks for that, the only thing is there is a problem with the elseif statement at the end of the code:

Players.ayxies.PlayerGui.SettingsUI.Frame.Core:62: Expected ‘end’ (to close ‘function’ at line 60), got ‘elseif’

fixxed the problem looked like i deleted too much without realising
anyways i edited the script and it should work as intended.

Thank you, that worked perfectly. I appreciate it. :slight_smile:

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