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