Hello all,

I couldn't think of a good title for this question so I just went with what I could think of. Anyway, recently I have been trying to make a feature which when you pick up an item from clicking it, it drops the item in the place the other item does, all good. But, when I go to pick up the item again, it doesn't give me the item nor drops my current item in my toolbox.

It is a Piggy like feature too, you pick up an item, and you drop the current one in the same position and can be easily picked back up.

The script for picking up the red key

local tool = game.ServerStorage.RedKey
local klone = tool:clone()

script.Parent.ClickDetector.MouseClick:connect (function(plr)
if plr.Backpack:FindFirstChild("OrangeKey") then
local OrangeKey = plr.Backpack.OrangeKey
script.Parent.Parent.OrangeKey.CFrame = CFrame.new(Vector3.new(-57.781, 2.239, -42.72))
OrangeKey:Destroy()
Instance.new("ClickDetector",script.Parent.Parent.OrangeKey)
script.Parent.Parent.OrangeKey.Transparency = 0
script.Parent.Parent.OrangeKey.Anchored = true
klone.Parent = plr.Backpack
script.Parent.ClickDetector:Destroy()
script.Parent.Transparency = 1
	else
klone.Parent = plr.Backpack
script.Parent.ClickDetector:Destroy()
script.Parent.Transparency = 1

end
end)

What the script is doing is checking if the user has the orange key, if they do, it will remove the item from the user and put the replica of the item in its place, which contains this script, this works for picking up the item normally with the swapping. The swapping also works once, so for example, if I had the Red Key and clicked on the Orange Key, it would remove the red key and place it in the place of the orange key, along with giving me the orange key and hiding it from the workspace. But then trying to repeat the action the other way doesn't work at all.

The script for picking up the orange key

local tool = game.ServerStorage.OrangeKey
local klone = tool:clone()

script.Parent.ClickDetector.MouseClick:connect (function(plr)
if plr.Backpack:FindFirstChild("RedKey") then
local RedKey = plr.Backpack.RedKey
script.Parent.Parent.RedKey.CFrame = CFrame.new(Vector3.new(75.838, 4.392, -60.388))
RedKey:Destroy()
Instance.new("ClickDetector",script.Parent.Parent.RedKey)
script.Parent.Parent.RedKey.Transparency = 0
script.Parent.Parent.RedKey.Anchored = true
klone.Parent = plr.Backpack
script.Parent.ClickDetector:Destroy()
script.Parent.Transparency = 1
	else
klone.Parent = plr.Backpack
script.Parent.ClickDetector:Destroy()
script.Parent.Transparency = 1

end
end)

Kind of is the same script as the red key but changed with the orange key values.

I have looked in the output system and nothing has shown up. Any ideas or solutions?