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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
noammao 294 Moderation Voter
6 years ago

instead of script.parent:remove try using

script.Parent:Destroy()

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

0
wait are you allowed to use MouseButton1Click on a part? User#20192 0 — 6y
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. noammao 294 — 6y
Ad
Log in to vote
0
Answered by
Bertox 159
6 years ago

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

Log in to vote
0
Answered by 6 years ago

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!

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. Le_Teapots 913 — 6y
1
Ehm, that's not a function I've ever seen before. (Line 1) Isn't it `Game:GetService('Players').LocalPlayer`? TheeDeathCaster 2368 — 6y
0
but i wanted one that takes very few lines..or one that can be explained User#20192 0 — 6y
0
Um i dont understand this..im not one of those master scripters User#20192 0 — 6y
Log in to vote
-1
Answered by
Kblow1 53
6 years ago
Edited 6 years ago

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)
0
That is very inefficient. Use a for loop instead. T0XN 276 — 6y
0
Ok so because its inefficient you -rep me? I answered his question but ok. Great job! Keep -rep people :) Kblow1 53 — 6y

Answer this question