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

How do u remove a object with a clickdetector?

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

✓ Accepted answer

: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.

5 comments

0

Yup works perfect, the bullet completely disappears now thanks a ton.

0

Most welcome. Please indent your code too!

0

Sorry i have no idea what indent means lmao

0

There should be a wiki article page about it. Indenting is hard to explain. It organizes the code better though.

0

o oke lol

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.

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