Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making a part spawn when I click a brick?

I made a ClickDetector brick that would spawn a part on top of it whenever a player clicked on it. It isn't working, unfortunately.

script.Parent.ClickDetector.MouseClick:connect(function()
	x = Instance.New("Part")
	x.BrickColor = BrickColor.New("Institutional White")
	x.Position = Vector3.New(12.5, 43.4, 29.5)
	x.Size = Vector3.New(1,1.2,1)
	x.Material("Foil")
	x.Shape("Ball")	
end)

(I'm not good with scripting so it would be amazing if I could get this to work)

2 answers

The reason it isn't working, is because the new instance doesn't have a parent! You created an object in nothing, and therefore there is nothing

To fix this, simply set a parent in it in one of 2 ways!

x = Instance.New("Part", parentLocation) --Set the parent the moment it is created!

or

x = Instance.New("Part")
x.Parent = parentLocation --Set it after the creation; your call.

2 comments

0

It hasn't changed anything. Line 2 is still red, and I have no idea why.

1

'.new'. Try .new, without a capital N. 

It fixed some things, but now line 5 is wrong.

 x.Position = Vector3.New(89.5, 3, -10.5)

I know that the positioning is above the button itself. The button is 1x1.

This discussion is preserved as it was. New answers, comments, and votes are closed.