Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I have a script that makes parts in workspace smooth plastic but how do I make it so it turns off?

This is a local script. The top half of the if statement works. The bottom half I need help with. The original material is the material of all the parts in workspace but the materials arent the same.

local Smooth = Enum.Material.SmoothPlastic
local UnSmooth = Enum.Material -- Original Material?

script.Parent.MouseButton1Click:Connect(function()
        if script.Parent.Text == "Off" then
        script.Parent.Text = "On"
        for i,v in pairs(workspace:GetDescendants()) do
            if v:IsA("Part")then
            v.Material = Smooth
        end
	end
    elseif script.Parent.Text == "On" then
           script.Parent.Text = "Off"
            for i,v in pairs(workspace:GetDescendants()) do
                if v:IsA("Part") then
                         v.Material = UnSmooth
                        end
                    end
                end
            end)

2 answers

✓ Accepted answer

Im the dude from the chat .-.

This is a way: (There are many better ways to do this btw)

local Smooth = "SmoothPlastic"

script.Parent.MouseButton1Click:Connect(function()
        if script.Parent.Text == "Off" then
        script.Parent.Text = "On"
        for i,v in pairs(workspace:GetDescendants()) do
            if v:IsA("Part")then

local oldMat = Instance.new("StringValue",v)
oldMat.Name = "Original_Mat"
oldMat.Value = v.Material

            v.Material = Smooth
        end
    end
    elseif script.Parent.Text == "On" then
           script.Parent.Text = "Off"
            for i,v in pairs(workspace:GetDescendants()) do
                if v:IsA("Part") then

local oldMat = v:FindFirstChild("Original_Mat")
if oldMat then
local get = #oldMat.Value
local getIt = string.Sub(oldMat.Value , 15,get)
                      v.Material = getIt
oldMat:Destroy()
else
print("Cant find lol")
--Alternative
end
                        end
                    end
                end
            end)

7 comments

0

btw the script from kingblaze_1000 is good

0

And I dont even tested mine sooooo

0

Thanks XD

0

let me edit it

0

Your code blocks are broken

0

*edited

0

*edited

Maybe try saving the original material of each part before it is turned smooth like this.

local Smooth = Enum.Material.SmoothPlastic
local UnSmooth = {}

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Text == "Off" then
		script.Parent.Text = "On"
		for i,v in pairs(workspace:GetDescendants()) do
			if v:IsA("Part")then
				table.Insert(UnSmooth, v.Name.." "..i " = " v.Material)
				v.Material = Smooth
			end
		end
	end
	elseif script.Parent.Text == "On" then
		script.Parent.Text = "Off"
		for i,v in pairs(workspace:GetDescendants()) do
			if v:IsA("BasePart") then --//This is better off BasePart
				for _,t in pairs(UnSmooth) do
					if string.match(t, v.Name) and string.match(t, tostring(i)) then
						v.Material = t
					end
				end
			end
		end
	end
end)

I think it won't work ;-;

Hopefully this worked for you and if it did please accept answer.

Thank you.

5 comments

0

That seems to be a smart way but he said that the Materials are different .-

0

Yeh the material will be stored differently for each part

0

Actually I'm not sure

0

If part 1 is stone and part 2 is wood then UnSmooth will be 'Wood' that means that all parts will be wood then .-.

0

Ima edit my script

This discussion is preserved as it was. New answers, comments, and votes are closed.