Hello. I was gonna make a FPS mode for the low-end players, but I can’t seem to get it work.
Here is script:
local button = script.Parent
button.MouseButton1Click:Connect(function()
for _, v in workspace:GetDescendants() do
if v:IsA("Basepart") then
v.Material = Enum.Material.Plastic
end
end
end)
Oh yea, also I want it so the material changes back to normal when I click the button again, and I want the settings saved.
You seem to have forgotten pairs(). And to return it back you’ve got to create a table and save the previous materials.
local previousMaterials = {}
previousMaterials[instance] = instance.Material --saving on a table to return it back later, of course you would loop through with this normally.
Be aware that other scripts changing the materials will cause conflict, you must also update new parts when they are added.
local button = script.Parent
local previousMaterials = {}
previousMaterials[instance] = instance.Material
local number = 1
button.MouseButton1Click:Connect(function()
if number == 0 then
number = 1
if number == 1 then
for _, v in ipairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
v.Material = Enum.Material.Plastic
end
end
end
end)
local button = script.Parent
local previousMaterials = {}
previousMaterials[instance] = instance.Material
local number = 1
button.MouseButton1Click:Connect(function()
if number == 0 then
number = 1
if number == 1 then
for _, v in ipairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
v.Material = Enum.Material.Plastic
end
end
end
end
end)
local button = script.Parent
local previousMaterials = {}
--previousMaterials[instance] = instance.Material
local number = 1
button.MouseButton1Click:Connect(function()
if number == 0 then
number = 1
if number == 1 then
for _, v in ipairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
v.Material = Enum.Material.Plastic
end
end
end
end
end)
local button = script.Parent
local previousMaterials = {}
local enabled = false
button.MouseButton1Click:Connect(function()
if not enabled then
enabled = true
for _, v in ipairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
previousMaterials[v] = v.Material --save it so we can return later (has to be implemented)
v.Material = Enum.Material.Plastic
end
end
end
end)
also the version with the number variable does not work since it starts on 1 but needs to be 0 to run, and on this situation it is better to use a boolean
If the part’s material is changed while the player is in FPS mode and the player disables it, the part’s material will be set to the one before the player enabled FPS mode.
New parts will not be set to plastic.
But hey i made it anyway:
local button = script.Parent
local previousMaterials = {}
local enabled = false
button.MouseButton1Click:Connect(function()
if not enabled then
enabled = true
for _, v in ipairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
previousMaterials[v] = v.Material
v.Material = Enum.Material.Plastic
end
end
else --else if it is enabled lets disable it
enabled = false
for _, v in ipairs(workspace:GetDescendants()) do
if v:IsA("BasePart") and previousMaterials[v] then --check if it's a basepart and if we saved it
v.Material = previousMaterials[v]
end
end
end
end)
if you don’t plan to change materials on parts this will work just fine, you could also use DescendantAdded to fix the new parts problem