Instance.new not functioning as intended

This simple script that places a part doesn’t work. Is there a fix?

local ClickDetector = script.Parent.ClickDetector

local function onClick()
		Instance.new("Part", game.ServerStorage)
		game.ServerStorage.brick.Parent = workspace
end
ClickDetector.MouseClick:Connect(onClick)
Error message

Screen Shot 2021-03-16 at 8.07.25 PM

Change brick to “Part”. Whenever you create one, it sets the name to the ClassName.

Also you can just get a reference to the new instance directy from the constructor.

local brick = Instance.new("Part")
brick.Parent = workspace

There’re a few things that are incorrect here. Here’s corrected code:

local ClickDetector = script.Parent.ClickDetector

local function onClick()
    local newPart = Instance.new("Part")
    newPart.Parent = game.Workspace
end
ClickDetector.MouseClick:Connect(onClick)

Let me know if you have any questions.

2 Likes