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

How do u remove a object with a clickdetector?

Asked by 6 years ago
local function OnClicked()
script.Parent:Remove()
end

parent.ClickDetector.MouseClick:connect(OnClicked)

I'm not the best scripter but would like to try scripting as it is a good skill to have along with building which I can build great enough now. But I can't find out how to make it where you get the darn bullet to disapear when u click on it. I already have a click detector and all but it still wont seem to work. I have a feeling I'm stuck using older code i knew back in the day but dont know how to do newer code. Any suggestions?

2 answers

Log in to vote
0
Answered by 6 years ago

:Remove() is deprecated.

Instead you can use

script.Parent:Destroy() (method destroys it completely)

or

game:GetService("Debris"):AddItem(script.Parent, 0) (don't use this unless you want to make it yield or wait until it can be destroyed, 0 is the amount of seconds until the item is removed.)

Also, like the previous answer, it is highly recommended to indent your code. This makes it easier to understand and can help you organize code better.

0
Yup works perfect, the bullet completely disappears now thanks a ton. Sergiomontani10 236 — 6y
0
Most welcome. Please indent your code too! User#18043 95 — 6y
0
Sorry i have no idea what indent means lmao Sergiomontani10 236 — 6y
0
There should be a wiki article page about it. Indenting is hard to explain. It organizes the code better though. User#18043 95 — 6y
0
o oke lol Sergiomontani10 236 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local function OnClicked()
    script.Parent:Destroy()
end

script.Parent.ClickDetector.MouseClick:connect(OnClicked)

Also, please indent your function's body, it makes it much easier to read.

Answer this question