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

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

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)

1 comment

0

:connect is deprecated, use :Connect instead

1 answer

✓ Accepted answer

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.

1 comment

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.

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