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!!!
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)
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)