Help preventing error

Im making a lock pick system so the door unlocks if the player is holding a lockpick, but if the player doesnt hold a lockpick I get an error and the script doesnt go to the else and play sound. Can someone help me prevent this

Check if the tool’s parent is the character.

if tool.Parent == Character then

Another way is to check for their humanoid:

if tool.Parent and tool.Parent:FindFirstChild("Humanoid") then

If you want to make sure that the player who uses the proximity is holding a tool do:

if player.Character and player.Character:FindFirstChild("LOCKPICK_TOOL_NAME") then
1 Like