My delete model script is not working

Hello, my delete meshpart script is not working. Can anyone help me?
This is my code. Also by the way the code you don’t see on the top is function module.Clicked(plr,item)
then the rest of the code continues.

	if plr then
		if plr.Character and not plr:FindFirstChild("Piggy") 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 object")
				
				
			end
			
		end
	end
end								
												
I have been trying for a long time to get this to work but it is not working.
Can anyone resolve this issue?
Thanks!
1 Like

what does the rest of the script look like? Where is the script(in studio)? What type of script is it?

1 Like

it is a module script here is the whole script and the script is inside of a regular script in server script service also sorry for the late reply.



function module.DropTools(plr,map,position)
	
	-- look for tools in the players Backpack
	
	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
	
	-- look for tools in your Character
	
		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("Piggy") 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 object")
				
				
			end
			
		end
	end
end								
												
																	
return module

Its too big to show the whole thing @MooskaisFlawless

Unfortunately, I cannot find the bug. Try using more print statements though to see which line of code is causing your script to not function the way you want it to. Also is there any errors in the output?

I have tried to see but my game requires 2 players and using the local server feature my code breaks so I will tweak some code to test it with just 1 player.

There are no errors so I have no idea whats wrong.