"Invalid value for enum Material" error

I am making a build system in Roblox right now, making sure that the blocks the player places will appear for the server too. I made a server script so the part will appear for the server; along with a remote event that fires when a local script runs it.

The issue is that I keep getting this error in the server script, “Invalid value for enum Material”. It happens on line 16. The server script is here:

local event = game.ReplicatedStorage.Build
local event2 = game.ReplicatedStorage.PartChange
local part = "Cube"

local function onPartChanged(value)
    local part = value
end

event2.OnServerEvent:Connect(onPartChanged)
--

local function onBuild(position, material, color)
    local clone = game.Workspace:FindFirstChild(part):Clone()
    clone.CastShadow = true
    clone.Color = Color3.fromRGB(color)
    clone.Material = material --error happens here
    clone.Transparency = 0
    clone.CanCollide = true
    clone.Position = position
    clone.Name = "PlacedPart"
    clone.Parent = game.Workspace
end

event.OnServerEvent:Connect(onBuild)

Here’s the local script:

script.Parent.Parent.PlayerGui:WaitForChild("BuildingGui")
local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
local event = game.ReplicatedStorage.Build

game.Workspace:FindFirstChild(script.Parent.Parent.PlayerGui.BuildingGui.MainFrame.CurrentPart.Value).Transparency = 0.5
mouse.Button1Down:Connect(function()
    if game.Workspace:FindFirstChild(player.PlayerGui.BuildingGui.MainFrame.CurrentPart.Value) ~= nil then
    local clone = game.Workspace:FindFirstChild(script.Parent.Parent.PlayerGui.BuildingGui.MainFrame.CurrentPart.Value):Clone()
    event:FireServer(clone.Position, player.PlayerGui.BuildingGui.MainFrame.ChangeMaterial.ButtonSelected.Value, player.PlayerGui.BuildingGui.MainFrame.ChangeColor.CurrentColor.Value)
    end
end)

Here’s my explorer:


My Local Script is in the PlayerScripts.

I looked around in the explorer and tested the game and saw what was the Material value, and it should be valid. I also looked up the error and it said that the error happened in CoreScripts on Mac, even though I’m on PC and this is not on a CoreScript.

I don’t know if this is an Engine Bug or what, but I’d like to know why this is happening.

what’s the value?
(30 characters)

I’m certain that there is no MaterialValue object, so material in the script is just a string or whatever the type of value it is. To make it the material you want, just do this.

clone.Material = Enum.Material[material]

I think this will work, and if it doesn’t make sure material is a string.

another problem i noticed is that you directly connect the OnServerEvent to onBuild, but the problem is that the Position argument is equal to the player.
do this instead:

local function onBuild(position, material, color)
    local clone = game.Workspace:FindFirstChild(part):Clone()
    clone.CastShadow = true
    clone.Color = Color3.fromRGB(color)
    clone.Material = material --error happens here
    clone.Transparency = 0
    clone.CanCollide = true
    clone.Position = position
    clone.Name = "PlacedPart"
    clone.Parent = game.Workspace
end

event.OnServerEvent:Connect(function(player, ...)
    onBuild(...)
end)
2 Likes

Thanks! This worked! (30 char)

1 Like