Help with Button Part Spawner

I want to click a part and make it spawn a brick. I’ve tried tinkering around but it’s just not working. I’ve read through it but it seems right.

local partSpawner = script.Parent

local function buttonClicked()
	
	local e = Instance.new("Part")
	e.Parent = workspace
	e.Position = Vector3.new(-116, 7.5, -121)
	
end

script.Parent.ClickDetector:Connect(buttonClicked)
2 Likes

You’re spawning the brick on -116, 7.5, -121, have you checked if it’s there?

1 Like

Use the MouseClick event. You’re connecting the function to the ClickDetector, not the actual click event itself. The last line should be:

script.Parent.ClickDetector.MouseClick:Connect(buttonClicked)
3 Likes

Here is a solution:

local partSpawner = script.Parent

local function buttonClicked()

local e = Instance.new("Part")
e.Parent = workspace
e.Position = Vector3.new(-116, 7.5, -121)

end
script.Parent.ClickDetector.Mouse1Click:Connect(buttonClicked)

Remember to look at the parts position: e.Position = Vector3.new(-116, 7.5, -121)
change it if needed.