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

Why don't my digging script work? A script where you click the part and it removes.

I entered a script into a part that says when you click it the part gets destroyed but it dont work! help!

script.Parent.MouseButton1Click:connect(function(player)
script.Parent:remove()
end)

I am doing this to make a game where you dig to find treasure...so i really need help.

4 answers

✓ Accepted answer

instead of script.parent:remove try using

script.Parent:Destroy()

script.Parent.MouseButton1Click:connect(function(player)
script.Parent:Destroy
end)

2 comments

0

wait are you allowed to use MouseButton1Click on a part?

0

No. You have to have a clickDetector inside of the part and the script inside of the clickDetector. And inside of the script you cant use MouseButton1Click. MouseButton1Click only works inside of GUI's. Use script.Parent.MouseClick:connect(function(player) instead.

A part doesn't have the function "MouseButton1Click". You have to add a ClickDetector into the part, and make a global Script

Try using this in a localscript. This will not require you to put ClickDetectors in everything because honestly that's just obnoxious and unneeded.

local Player=game("GetService","Players").LocalPlayer
local Mouse=Player:GetMouse()

Mouse.Button1Down:connect(function()
	local Target=Mouse.Target
	if Target:IsA("BasePart") then
		Target:Destroy()
	end
end)

Hope I helped!

4 comments

0

That's a pretty effective method, worth keeping in mind tho that if what Daniel wants is for only certain parts to be destroyable then another condition addressing that is required on line 6.

1

Ehm, that's not a function I've ever seen before. (Line 1) Isn't it Game:GetService('Players').LocalPlayer?

0

but i wanted one that takes very few lines..or one that can be explained

0

Um i dont understand this..im not one of those master scripters

Hey! This Should work.. but you need to do a couple of steps.

1.) First put a click detector inside of the part you want to go away.

2.) Then in insert a script inside of the part. And put this script inside. And your all set!

local sp = script.Parent
function DestroyBlock()
	sp.Transparency = 0.1
	wait()
	sp.Transparency = 0.2
	wait()
	sp.Transparency = 0.3
	wait()
	sp.Transparency = 0.4
	wait()
	sp.Transparency = 0.5
	wait()
	sp.Transparency = 0.6
	wait()
	sp.Transparency = 0.7
	wait()
	sp.Transparency = 0.8
	wait()
	sp.Transparency = 0.9
	wait()
	sp:Destroy()
end

script.Parent.ClickDetector.MouseClick:Connect(DestroyBlock)

I added the Transparency to give it a very nice effect. Enjoy!

EDIT: If you didnt want the nice effect heres the simple script

function DestroyBlock()
	script.Parent:Destroy()
end

script.Parent.ClickDetector.MouseClick:Connect(DestroyBlock)

2 comments

0

That is very inefficient. Use a for loop instead.

0

Ok so because its inefficient you -rep me? I answered his question but ok. Great job! Keep -rep people :)

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