I need help making a Brick appear when another Brick is clicked

So i’m trying to make it so if you click a brick another brick will appear
I made a code:

local NewPart = Instance.new (“Part”)

local ClickDectector = Instance.new (“ClickDetector”)

NewPart.Parent = workspace

NewPart.Position = Vector3.new(69, 0.5, -49)

ClickDectector.Parent = NewPart

local function Clicked ()

local NewPart2 = Instance.new

NewPart2.Parent = workspace

NewPart2.Position = Vector3.new (85, 0.5, -50)

end

NewPart.ClickDetector.MouseClick:Connect(Clicked)

It errors at line 10 for some reason

Isnt it better to insert an ClickDetector manually?Also,you could have used transparency,instead of moving the brick,i suggest using this code:

script.Parent.MouseClick:connect(function()
    local NewPart = Instance.new("Part")
    NewPart.Parent = game.Workspace(The NewPart parent)
    NewPart.Transparency = 1(Amount of transparency)
    NewPart.Position = Cframe.new(x,y,z)(Coordinates/Position)
end)

Also,everytime you want to write an code,type this

`(Type this 3 times)

`(Make an other below,with also 3 times)

Then it should look like this:

Code Here 1 true "Hello" --Good code

what is the error on line 10? and which line is line 10

I counted,and is supposed to be the “end”

1 Like

First please indent your code and preformat it, so it is easier to read.

Second make sure everything is spelled correctly, it looks like you put a space in between the parenthesis and Clicked from your function.

Also there are better ways to make this script, first off why do you make a part in the beginning, when you can manually make it with studio.

1 Like

what instance do you want to create exactly? specify please

also don’t use a local script in the part unless you’re going to clone the script sometime later to someplace it would actually be functional.

@Humanitasm create a part by using Instance.new(“Part”) for example

1 Like

Line 10 is NewPart2.Parent = workspace
The error is ServerScriptService.Script:10: attempt to index global ‘NewPart2’ (a function value)

the error is here, you forgot to put (“Part”)

2 Likes

Yes, I know i’m just stupid I forgot that

You were supposed to count the code 1 to 10,and not the text 1 to 10

Also i’am gonna make an sort of cleaner version of your code.

local NewPart = Instance.new (“Part”)
    NewPart.Parent = workspace
    NewPart.Position = Vector3.new(69, 0.5, -49)

local ClickDetector = Instance.new (“ClickDetector”)--ClickDetector
    ClickDetector.Parent = NewPart

NewPart.ClickerDetector.MouseClick:connect(function()--Function

local NewPart2 = Instance.new("Part")--NewPart2
    NewPart2.Parent = workspace
    NewPart2.Position = Vector3.new (85, 0.5, -50)
end)

If this code doesnt work,then i dont know how to help you,hope it helps tho.

Aside from what I and others have mentioned (to specify what instance you want to generate) you could also minimize code by letting the click detector exist on its own and then only using the code to detect clicks, generally speaking, the fewer the code, the better the performance*.

your script wont’ work with simple errors like that,
it’s advised to quickly overlook whatever your code’s supposed to do and how you wrote it before posting.

1 Like

I’m trying to practice with Instance.new