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

How do I make a When clicked, destroy block script?

I have already tried this script with no success.

-- I put this script as a child of a Part called Part.
local Block = game.Workspace.Part
function DestroyBlock ()
	Part:Destroy()
end


Block.ClickDetector.MouseClick:Connect(DestroyBlock())

If you could help, I would be very happy.

1 comment

0

btw, you can replace "Part" in line 4 to "Block" and it wil work

4 answers

workspace.Part.ClickDetector.MouseClick:Connect(function()
    script.Parent:Destroy()
end)

This should work considering you placed the script inside a part.

~Dan_PanMan, advanced scripter.

Hello, admin4lifenow!

Test out this script instead. I don't see an error in your script, but I hope that this ones works for you:

Put this script inside of the ClickDetector

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent:Destroy()
end)

3 comments

0

mousebutton1click is not a function in clickdetector

0

It sadly didn't work.

0

Sorry, I meant MouseClick. Dan has the correct solution

``local Block = script.Parent

Block.ClickDetector.MouseClick:Connect(function() Block:Destroy() end) ``

Make sure you have a Clickdetector in your part so u can click it! also use script.parent instead of game.workspace in case you move the part it will still work.

Hi!

This should be able to work:

local cd = Instance.new("ClickDetector",script.Parent)
cd.MouseClick:Connect(function()
	script.Parent:Destroy()
end)

Make sure that this script is inside the part that you want to be destroyed.

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