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

My delete once touched script is not working, there are no errors, can someone help?

Asked by 4 years ago

I am trying to make a script where if someone clicks a card they get it, but it also deletes the object in the workspace. Below is the code.

function touch(x)
    local y = x.Backpack
    local z = game.Lighting["[SCP] Card-L1"]
    z:Clone().Parent = y
    script.Disabled = true
    script.Parent.ClickDetector.MaxActivationDistance = 1
    Instance.Remove(script.Parent)
end

script.Parent.ClickDetector.MouseClick:connect(touch)
0
:connect is deprecated, use :Connect instead turtle2004 167 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

TBH, I have never seen anyone use Instance.Remove(). Where did you get that from?

The correct way to delete instances is via the :Destroy() method. You want something like:

script.Parent:Destroy()

Also, I noticed that you use :connect(). As @turtle2004 pointed out, that function is deprecated (aka old) and you should you use :Connect(). Additionally, it is generally discouraged to use Lighting for storage. We have ServerStorage and ReplicatedStorage for that. Also also, please name your variables properly. Names like x and y are hard to debug, especially when you get into more complicated code.

0
Ah wait now I realize what Instance.Remove() is. It's the deprecated :Destroy(), and you are calling it in an unusual way which I forget how it's called. From your code, however, I have a feeling you are expecting x to be a Player. It cannot, as it will always be a physical part. You need to use Players:GetPlayerFrpmCharacter() to get the Player object. RiskoZoSlovenska 378 — 4y
Ad

Answer this question