Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making a part spawn when I click a brick?

Asked by 10 years ago

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

Log in to vote
0
Answered by
OniiCh_n 410 Moderation Voter
10 years ago

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.
0
It hasn't changed anything. Line 2 is still red, and I have no idea why. Marioluigi35 7 — 10y
1
'.new'. Try .new, without a capital N.  infalliblelemon 145 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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.

Answer this question