Hey there! This script is intended to destroy a tool when a player presses backspace instead of dropping it however the script won't seem to work and I can't identify the problem. Any help would be appreciated :)

local tool = script.Parent
tool.CanBeDropped = false

local UIS = game:GetService("UserInputService")

function onKeyPress(inputObject, gameProcessedEvent) -- Create function
    if inputObject.KeyCode == Enum.KeyCode.Backspace then -- If the player pressed Backspace
        tool:Destroy()
    end
end

UIS.InputBegan:connect(onKeyPress) 

P.S: I'm rather new to Lua.

2 comments

1

It's probably because the Backspace already handles tool dropping, this means that it is used in the ContextActionService by the corescripts. You can try to use https://developer.roblox.com/en-us/api-reference/function/ContextActionService/BindActionAtPriority to override it. (Give priority of 1000)

1

Yes, you want to use ContextActionService. Take a look at this https://developer.roblox.com/en-us/api-reference/class/ContextActionService