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

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

Asked by 4 years ago

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.

0
btw, you can replace "Part" in line 4 to "Block" and it wil work Dan_PanMan 227 — 4y

4 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago
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.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
mousebutton1click is not a function in clickdetector Dan_PanMan 227 — 4y
0
It sadly didn't work. admin4lifenow -6 — 4y
0
Sorry, I meant MouseClick. Dan has the correct solution Amanda314159 291 — 4y
Log in to vote
0
Answered by
fastlocks -10
4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.

Answer this question