I wrote a script to place a block:
local rs = game.ReplicatedStorage local event = rs.GrassPlace local current = workspace.CurrentBlock local TemplateFolder = game.ServerStorage.TemplateBlocks local blockValue = game.ServerStorage:FindFirstChild(current.Value) current.Value = "Brick" function place(plr,target,blocktype) if current then local blockInFolder = TemplateFolder[blockValue.Value] if blockInFolder then local newBlock = TemplateFolder[blockValue.Value]:Clone() end newBlock.Parent = workspace.Blocks newBlock.Size = Vector3.new(4,4,4) newBlock.Anchored = true newBlock.Name = current.Value newBlock.CFrame = CFrame.new(target.Position) + Vector3.new(0,4,0) newBlock.Parent = workspace end end event.OnServerEvent:Connect(place)
It says newBlock isn't defined, what is wrong??
If blockValue is the name of your block inside TemplateFolder that you want to clone, you need to find the block and then clone it. That is what the following code does:
local blockInFolder = TemplateFolder[blockValue.Value]
if(blockInFolder)then local newBlock = TemplateFolder[blockValue.Value]:Clone() end
Replace line 11 with the following code above.
[EDIT]: My bad, make sure you have the rest of the code changing newBlock in the same scope(area) as where you made the new block variable.
local rs = game.ReplicatedStorage local event = rs.GrassPlace local current = workspace.CurrentBlock local TemplateFolder = game.ServerStorage.TemplateBlocks local blockValue = game.ServerStorage:FindFirstChild(current.Value) current.Value = "Brick" function place(plr,target,blocktype) if current then local blockInFolder = TemplateFolder[blockValue.Value] if blockInFolder then local newBlock = TemplateFolder[blockValue.Value]:Clone() newBlock.Parent = workspace.Blocks newBlock.Size = Vector3.new(4,4,4) newBlock.Anchored = true newBlock.Name = current.Value newBlock.CFrame = CFrame.new(target.Position) + Vector3.new(0,4,0) newBlock.Parent = workspace end end end event.OnServerEvent:Connect(place)