--Drop on Death Script
--Unless you know what you're doing, do not modify this script.
if script.Parent.Parent:IsA("Backpack") then --This ensures that the tool's parent is a player's backpack.
	local player = script.Parent.Parent.Parent --This identifies the player with the tool.
	local character = player.Character --This identifies the character holding the tool.
	local humanoidrootpart = character:FindFirstChild("HumanoidRootPart") --This finds the HumanoidRootPart of the character.
	local humanoid = character:FindFirstChild("Humanoid") --This identifies "Humanoid".
	local characterscript = script.CharacterScript:Clone() --This clones the CharacterScript.
	characterscript.Parent = character --This puts the CharacterScript inside the character.
	characterscript.Tool.Value = script.Parent --This sets the tool value to the tool this script is inside.
	characterscript.Player.Value = player --This sets the player value to the player with the tool.
	characterscript.Disabled = false --This enables the CharacterScript clone.
	if humanoid ~= nil and humanoidrootpart ~= nil then --This ensures that "Humanoid" and "HumanoidRootPart" exist inside the character.
		humanoid.Died:Connect(function() --This detects the death of the character.
			script.Parent.Handle.CFrame = CFrame.new(humanoidrootpart.Position) --This sets the position of the handle to the character's position.
			script.Parent.Parent = game.Lighting --This puts the tool into Lighting so nobody can pick it up.
		end)
	end
elseif script.Parent.Parent:IsA("Model") then --If the tool's parent is a model, then the code below will run instead.
	local character = script.Parent.Parent --This identifies the character holding the tool.
	local player = game.Players:GetPlayerFromCharacter(character) --This identifies the player of the character.
	local humanoidrootpart = character:FindFirstChild("HumanoidRootPart") --This finds the HumanoidRootPart of the character.
	local humanoid = character:FindFirstChild("Humanoid") --This identifies "Humanoid".
	local characterscript = script.CharacterScript:Clone() --This clones the CharacterScript.
	characterscript.Parent = character --This puts the CharacterScript inside the character.
	characterscript.Tool.Value = script.Parent --This sets the tool value to the tool this script is inside.
	characterscript.Player.Value = player --This sets the player value to the player with the tool.
	characterscript.Disabled = false --This enables the CharacterScript clone.
	if player ~= nil and humanoid ~= nil and humanoidrootpart ~= nil then --This ensures that the player exists and "Humanoid" and "HumanoidRootPart" exist inside the character.
		humanoid.Died:Connect(function() --This detects the death of the character.
			script.Parent.Handle.CFrame = CFrame.new(humanoidrootpart.Position) --This sets the position of the handle to the character's position.
			script.Parent.Parent = game.Lighting --This puts the tool into Lighting so nobody can pick it up.
		end)
	end
end
script.Parent.AncestryChanged:Connect(function() --This detects a change of the tool's parent.
	if script.Parent.Parent:IsA("Backpack") then --This ensures that the tool's parent is a player's backpack.
		local player = script.Parent.Parent.Parent --This identifies the player with the tool.
		local character = player.Character --This identifies the character holding the tool.
		local humanoidrootpart = character:FindFirstChild("HumanoidRootPart") --This finds the HumanoidRootPart of the character.
		local humanoid = character:FindFirstChild("Humanoid") --This identifies "Humanoid".
		local characterscript = script.CharacterScript:Clone() --This clones the CharacterScript.
		characterscript.Parent = character --This puts the CharacterScript inside the character.
		characterscript.Tool.Value = script.Parent --This sets the tool value to the tool this script is inside.
		characterscript.Player.Value = player --This sets the player value to the player with the tool.
		characterscript.Disabled = false --This enables the CharacterScript clone.
		if humanoid ~= nil and humanoidrootpart ~= nil then --This ensures that "Humanoid" and "HumanoidRootPart" exist inside the character.
			humanoid.Died:Connect(function() --This detects the death of the character.
				script.Parent.Handle.CFrame = CFrame.new(humanoidrootpart.Position) --This sets the position of the handle to the character's position.
				script.Parent.Parent = game.Lighting --This puts the tool into Lighting so nobody can pick it up.
			end)
		end
	elseif script.Parent.Parent:IsA("Model") then --If the tool's parent is a model, then the code below will run instead.
		local character = script.Parent.Parent --This identifies the character holding the tool.
		local player = game.Players:GetPlayerFromCharacter(character) --This identifies the player of the character.
		local humanoidrootpart = character:FindFirstChild("HumanoidRootPart") --This finds the HumanoidRootPart of the character.
		local humanoid = character:FindFirstChild("Humanoid") --This identifies "Humanoid".
		local characterscript = script.CharacterScript:Clone() --This clones the CharacterScript.
		characterscript.Parent = character --This puts the CharacterScript inside the character.
		characterscript.Tool.Value = script.Parent --This sets the tool value to the tool this script is inside.
		characterscript.Player.Value = player --This sets the player value to the player with the tool.
		characterscript.Disabled = false --This enables the CharacterScript clone.
		if player ~= nil and humanoid ~= nil and humanoidrootpart ~= nil then --This ensures that the player exists and "Humanoid" and "HumanoidRootPart" exist inside the character.
			humanoid.Died:Connect(function() --This detects the death of the character.
				script.Parent.Handle.CFrame = CFrame.new(humanoidrootpart.Position) --This sets the position of the handle to the character's position.
				script.Parent.Parent = game.Lighting --This puts the tool into Lighting so nobody can pick it up.
			end)
		end
	end
end)