How do I fix using backspace to drop my tool from deleting all the scripts?

Hi, I want to fix my issue of whenever I press backspace It just deletes all my scripts in it. I have tried looking for a solution but I couldn’t find one so I decided to ask for help.

I’ve tried disabling dropping and trying to make the drop key different, but it just ends up stuck on the player’s hand

(example):
wow

Here’s what the code looks like.


local tool = script.Parent
local playerInputService = game:GetService(“UserInputService”)

local equipped = false

tool.Equipped:Connect(function()
equipped = true
tool.Handle.PressE.Enabled = false
end)
tool.Unequipped:Connect(function()
equipped = false
end)
playerInputService.InputBegan:Connect(function(input)
if equipped == true then
if input.keyCode == Enum.KeyCode.P then
tool.Parent = workspace
wait(0.1)
tool.Handle.PressE.Enabled = true
equipped = false
end
end
end)

Are there any tips on how I can combat this bug?

(also sorry if I put this under the wrong category couldn’t decide if this should’ve been code review or scripting support)

Please be more clear, if the player drops the tool into the workspace then the scripts get deleted?

Yes if they drop it into the workspace the script gets deleted

Can we please have a video or screenshot?

Here it is in my hands but yet its parent is the workspace.

Thats odd, maybe try destroying or removing the tool when it is the workspace?
use the :Remove or the :Destroy async

I had to but back in the scripts.

Ok thank you i tried and it worked :+1:

If you want a script that automatically deletes it here it is:

local tool = script.Parent

if tool.Parent == workspace then
tool:Remove