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.