How do I make it so that when a player has 2 instances of a tool in their inventory, the tools get replaced by another tool?

Hello, this is my first post, I apologize if I did anything wrong here.

I need help making a script that detects if the player has 2 instances of a certain tool in their inventory, if they do, then the script will destroy said tools and replace them with a new tool.

I’ve tried doing a few scripts on that but none of them work properly.
The issue is that the script apparently doesn’t do anything, as if it didn’t exist.

Here’s the script I’ve been working with:

-- The parent of this script is ReplicatedStorage
local localPlayer = game.Players.LocalPlayer
local rockTool = game.Players.LocalPlayer.Backpack:FindFirstChild("Rock")

if rockTool then
	rockTool:Destroy()
	script.Parent.Rock2:Clone()
	script.Parent.Rock2:Clone().Parent = localPlayer.Backpack
end

Any help is appreciated.

If your script is parented to ReplicatedStorage, it does not run. Parent it to StarterPlayerScripts inside of StarterPlayer.