When I first pick up a key it works but I cant change a key for some reason

Script:

local module = {}

function module.DropTools(plr,map,position)
	
	--
	
		for i, tool in pairs(plr.Backpack:GetChildren()) do
			
			if tool:IsA("Tool") and game.ServerStorage.KeyHandles:FindFirstChild(tool.Name) then
			    
			   local clone = game.ServerStorage.KeyHandles:FindFirstChild(tool.Name):Clone()
			   
		       if clone:IsA("Model") then
			         clone:SetPrimaryPartCFrame(CFrame.new(position))
			    else
				     clone.Position = position
		         end	
			   
					clone.Parent = map.Items
					
					tool:Destroy()
					
			end
			
		end
				
	--
			for i, tool in pairs(plr.Character:GetChildren()) do
			
			if tool:IsA("Tool") and game.ServerStorage.KeyHandles:FindFirstChild(tool.Name) then
			    
			   local clone = game.ServerStorage.KeyHandles:FindFirstChild(tool.Name):Clone()
			   
		       if clone:IsA("Model") then
			        clone:SetPrimaryPartCFrame(CFrame.new(position))
			    else
				    clone.Position = position
		         end	
			   
					clone.Parent = map.Items
					
					tool:Destroy()
					
			end
			
		end
	
	
end


function module.Clicked(plr,item)
	if plr then
		if plr.Character and not plr:FindFirstChild("Cookie") then
		
		local position
		
			if item:IsA("Model") then	
				position = item.PrimaryPart.Position
			else
				position = item.Position
			end	
			
			module.DropTools(plr,game.Workspace.Map,position)
			print("Dropped Keyhandles")
			
			if game.ServerStorage.Tools:FindFirstChild(item.Name) then
				
				local clonedTool = game.ServerStorage.Tools[item.Name]:Clone()
				clonedTool.Parent = plr.Backpack
				
			    plr.Character.Humanoid:EquipTool(clonedTool)
			
			    item:Destroy()
			
			print("Equipped the tool")
				
			end
			
			
		end
	end
end


return module

4 comments

0

Elaborate.

0

Wdym by that

0

he's saying to make your problem more clear

0

Is this a module script?