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

My script to get the color and material not working, what is wrong???

Asked by 4 years ago
Edited 4 years ago

So, I made a script to get a two values, then make a part using those. I have a StringValue called current, which would keep a value like "Brick" and a Color3Value called CurrentColor which would contain an RGB value, like "248, 0, 9" and when I try to reference them in a script to make a block out of them, it errors. My script is:

local rs = game.ReplicatedStorage
local event = rs.GrassPlace
local current = workspace.Current
local color = workspace.CurrentColor

function place(plr,target,blocktype)
    local newBlock = Instance.new("Part")
    newBlock.Size = Vector3.new(4,4,4)
    newBlock.Anchored = true
    newBlock.Material = current
    newBlock.BrickColor = color.Value
    newBlock.Name = current.Value
    newBlock.CFrame = CFrame.new(target.Position) + CFrame.new(0,4,0)
    newBlock.Parent = workspace
end

event.OnServerEvent:Connect(place)

I also have a script inside a GUI that changes the "Current" value. If it helps, that script is:

local current = workspace.Current
local colorValue = workspace.CurrentColor

script.Parent.MouseButton1Click:Connect(function()
    current.Value = "Brick"
    colorValue.Value = script.Color.Value
end)

Please help me!!!

0
All you really need to worry about are lines 10 and 11. NickIsANuke 217 — 4y
0
or lines 3 and 4 NickIsANuke 217 — 4y
0
IDK lol NickIsANuke 217 — 4y
0
Enum.Material.current? greatneil80 2647 — 4y
View all comments (4 more)
0
change line 10 to newBlock.Material = current greatneil80 2647 — 4y
0
Also you didn't input a brick color for line 11 greatneil80 2647 — 4y
0
newBlock.Color = Color3.FromRGB(color.Value) -- try that greatneil80 2647 — 4y
0
Workspace.BlockPlacement:13: attempt to call field 'FromRGB' (a nil value) NickIsANuke 217 — 4y

2 answers

Log in to vote
0
Answered by
lucas4114 607 Moderation Voter
4 years ago

First, if you want to use a variable as a key for any table, you use table[variable], or Enum.Material[current] in this case.

Second, to make a BrickColor from a Color3 value, you can do BrickColor.new(color) or insert the RGB values separately BrickColor.new(color.r, color.g, color.b)

Fixed code:

local rs = game.ReplicatedStorage
local event = rs.GrassPlace
local current = workspace.Current.Value
local color = workspace.CurrentColor.Value

function place(plr,target,blocktype)
    local newBlock = Instance.new("Part", workspace)
    newBlock.Size = Vector3.new(4,4,4)
    newBlock.Anchored = true
    newBlock.Material = Enum.Material[current]
    newBlock.BrickColor = BrickColor.new(color)
    newBlock.Name = current
    newBlock.CFrame = CFrame.new(target.Position) + Vector3.new(0,4,0)
end

event.OnServerEvent:Connect(place)
0
Your code gave me the error "Is not a valid EnumItem." NickIsANuke 217 — 4y
0
Also, current is not a table, as I mentioned it holds a value like "Brick" or "Grass" NickIsANuke 217 — 4y
0
current is not the table, Enum.Material is the table, current is the variable that is the key for the table, so it uses table[key], and the error "Is not a valid EnumItem means your value is not a valid material, I tested it using "Brick" and it works, if you misspelled something as "Brickk" it will show that error, you can test it in the command line like this: print(Enum.Material["Brick"]) lucas4114 607 — 4y
0
That works, I didn't mis spell it, it still says "Is not a valid EnumItem." NickIsANuke 217 — 4y
0
What material are you trying to use? What value do you have for current? lucas4114 607 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The reason it because your doing BrickColor.color() not color.Value Your also adding a Vector3 to a CFrame; fixed that too

local rs = game.ReplicatedStorage
local event = rs.GrassPlace
local current = workspace.Current
local color = workspace.CurrentColor

function place(plr,target,blocktype)
    local newBlock = Instance.new("Part")
    newBlock.Size = Vector3.new(4,4,4)
    newBlock.Anchored = true
    newBlock.Material = current.Value
    newBlock.Color3= color.Value
    newBlock.Name = current.Value
    newBlock.CFrame = CFrame.new(target.Position) + CFrame.new(0,4,0)
    newBlock.Parent = workspace
end

event.OnServerEvent:Connect(place)

0
Ok, It still says "Is not a valid EnumItem." I am updating the question with one of my scripts. NickIsANuke 217 — 4y
0
Can you post the console error? the8bitdude11 358 — 4y
0
Invalid value "" for enum Material NickIsANuke 217 — 4y
0
Now it gives me NickIsANuke 217 — 4y
0
Invalid value for enum Material NickIsANuke 217 — 4y

Answer this question