Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Please help with String Values?

Asked by 9 years ago

So I have a very simple question but for some reason I am having a hard time on it. I was using this script to change the Drop color of the Drop based on the BrickColorValue. Then I made a model with buttons that when you click it, it changes the BrickColorValue's Value to the color of the Button.

wait(1)
for i,v in pairs(script.Parent.Buttons:GetChildren()) do
    if v:FindFirstChild("ClickDetector") then
        v.ClickDetector.MouseClick:connect(function()
            script.Parent.Color.BrickColor = v.BrickColor
            script.Parent.Parent.Parent.DropColor.Value = v.BrickColor
        end)
    end
end

That works fine and dandy. I then wanted to add the same sorta thing, but to change the Material. I used a String Value for this but when you click on the button it doesn't change the Material at all this is the script I have so far.

wait(1)
for i,v in pairs(script.Parent.Buttons:GetChildren()) do
    if v:FindFirstChild("ClickDetector") then
        v.ClickDetector.MouseClick:connect(function()
            script.Parent.Color.Material = v.Material
            script.Parent.Parent.Parent.DropMaterial.Value = v.Material
        end)
    end
end

Can you please help me figure out the problem?

1 answer

Log in to vote
2
Answered by 9 years ago

The Material property of a BasePart is actually an Enum and not a string. If you want to save it in a StringValue you can use the tostring method.

 script.Parent.Parent.Parent.DropMaterial.Value = tostring(v.Material)

Example Value:

Enum.Material.Plastic


If you wanted the value to just be the name of the enum you use the match function. The pattern I used finds any letters that are at the end of the string.

 script.Parent.Parent.Parent.DropMaterial.Value = tostring(v.Material):match("%a+$")

Example Value:

Plastic

Ad

Answer this question