Tool scripts stop working when the tool is moved into the workspace

I am trying to make it so that whenever a player dies, any tool that they have in their backpack or character drops (moves into the workspace). When another player touches the tool, it is meant to go into their backpack. The pickup script works fine once if I were to put it in the workspace directly but once the drop tool script has been ran. The pickup script just breaks entirely and you cannot pick it up again.

The drop tool script in startercharacterscripts:

local hadToolEquipped = false

humanoid.Died:Connect(function()
	for i, tool in pairs(character:GetChildren()) do
		if tool:IsA("Tool") then
			hadToolEquipped = true
			tool.Parent = game.ReplicatedStorage
			print("hadtoolequpped true")
		end
	end
	
	for i, tool in pairs(backpack:GetChildren()) do
		if tool:IsA("Tool") then
			hadToolEquipped = true
			tool.Parent = game.ReplicatedStorage
			print("hadtoolequpped true")
		end
	end
end)

player.CharacterRemoving:Connect(function(character)
	print("character removed!")
	for i, tool in pairs(backpack:GetChildren()) do
		if tool:IsA("Tool") and tool:FindFirstChild("Handle") then
			tool.Parent= game.Workspace
			tool.Handle.CFrame = character.HumanoidRootPart.CFrame
		end
	end
	if hadToolEquipped == true then
		local equippedTool = game.ReplicatedStorage:FindFirstChildOfClass("Tool")
		equippedTool.Parent = game.Workspace
		equippedTool.Handle.CFrame = character.HumanoidRootPart.CFrame
		print("revolver added back!")
	else
		print("revolver not added back")
	end
end)

The pickup gun script:

players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		print("connected to revolver function")
		script.Parent.Touched:Connect(function(Hit)
			print("revolver interacted")
			if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
				local backpack = Player:WaitForChild("Backpack")
				local player = players:GetPlayerFromCharacter(Hit.Parent)
				print("humanoid found")
				
				
				
				
				if player then
				script.Parent.Parent.Parent = player:WaitForChild("Backpack")
				print(script.Parent.Parent.Parent)
						print("successfully placed revolver in backpack")
				else
					print("failed to place into backpack")
				
			end
		end
	end)
	end)
end)

Any help would be nice. Thanks.

1 Like

Why would you need a pickup script when you can pick it up naturally?

Yes. I would have done it without a script but for some reason picking it up naturally does not work. I have checked the properties of both the handle and the tool and cannot seem to find out why it will not pick up naturally. Is there a way to do it with or without a script per chance?

I’m not sure what the problem could be if you can’t pick it up naturally, and I’m also not sure why the pickup script exactly breaks, but look, what I found is a blunder.

players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		print("connected to revolver function")
		script.Parent.Touched:Connect(function(Hit)

You connected the Touched event inside the CharacterAdded event. That won’t make the Touched event fired only when the Character touches it, but the Touched event will fire when ANYONE touches it. So if a lot of player joined, it can cause problem.

Secondly, I don’t suggest using script.Parent.Parent.Parent to find your tool. You can easily mess up sometimes. You should use Instance | Roblox Creator Documentation (“Tool”) so you can find the first parent that is a tool isntead of doing that.

I think I might know what the problem is now, look at

player:WaitForChild("Backpack")

The problem should be that you are trying to wait for Backpack. But I’m sure Roblox defines Backpack as a property of player instead of the actual instance. So, just do player.Backpack as the Backpack is instantly in player when u join in.

Thank you for the help. I just found out the reason. I can pick up the same tool naturally in another game but in my current game, it does not work.