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.
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
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)